The invention relates to a high strength heat-resistant magnesium alloy containing rare earths of the technical field of metallic materials and a preparation method thereof. The magnesium alloy comprises the following components according to the mass percent: Y with more than or equal to 3% and less than or equal to 16%, Gd with more than or equal to 0% and less than or equal to 10%, Ca with more than or equal to 0.3% and less than or equal to 5%, Zr with more than or equal to 0.1% and less than or equal to 1.5%, and one or a plurality of Nd, Si, Sb, Ti, Sn, Sr, Bi, Cd, Nd with more than or equal to 0% and less than or equal to 5%, Si with more than or equal to 0% and less than or equal to 5%, Sb with more than or equal to 0% and less than or equal to 5%, Ti with more than or equal to 0% and less than or equal to 5%, Sn with more than or equal to 0% and less than or equal to 5%, Sr with more than or equal to 0% and less than or equal to 5%, Bi with more than or equal to 0% and less than or equal to 5%, Cd with with more than or equal to 0% and less than or equal to 5%, and the rest is Mg and impurities. The magnesium alloy is obtained by using melting and the subsequent heat treatment. The magnesium alloy not only can serve as casting magnesium alloy but also can serve as the deformation magnesium alloy and has better predominant mechanical property compared with the WE series commercial magnesium alloy.