The mechanical properties and the electronic structures of transition metal compounds ZrB3 and NbB3 (m-AlB2, OsB3 and MoB3 structures) under high-pressure are studied by using the first-principles within density functional theory. It was found that m-AlB2 is the most stable structure under normal pressure. The pressure-induced phase transition occurs at the pressure of 40 Gpa, OsB3 structure becomes the most stable one under high pressure. m-AlB2-NbB3 has a maximum shear modulus of 204 GPa, the highest Debye temperature of 921 K, and the highest hardness of 27.3 GPa. The harnesses are estimated to be 24.9 GPa, 22.6 GPa and 19.8 GPa for MoB3-NbB3, OsB3-NbB3 and m-AlB2-ZrB3, respectively. The calculated density of states (DOS) illustrated that the electronic structures of considered compounds are governed by the strong hybridization between M-4d and B-2p states. All compounds are metallic.