The invention discloses a high-strength and heat-resistant magnesium alloy containing two rare earths. The high-strength and heat-resistant magnesium alloy containing the two rare earths comprises the components as follows: 14.0-17.0wt% of Y rare earth, namely Gd, Y and Er, 0.5-2.5wt% of Ce rare earth, namely one or several of La, Ce, Pr, Nd and Sm, 0.3-1.0wt% of Zr, impurities and the balance of Mg, wherein Gd is 11.0-15.0wt%, Y is 0.5-4.0wt% and Er is 0.5-2.0wt%; the content of Nd and Sm elements is 0.2wt% or less of the total amount of the magnesium alloy, or 0; the impurities including Fe, Si, Mn and a small amount of chloride; Fe is less than or equal to 0.002wt %, Si is less than or equal to 0.04wt%, Mn is less than or equal to 0.02wt%, and chloride is less than or equal to 0.002wt%; the impurity content is more than 0; Er in the Y rare earth can be replaced by one or several of Tb, Dy, Ho, Yb and Tm. The magnesium alloy has relatively high mechanical properties at room temperature and relatively stable high temperature creep resistance, and has relatively high yield rate of rare earth elements in the smelting process.