The invention discloses a magnesium alloy with hot cracking resistance and low linear shrinkage, and belongs to the magnesium alloy field. The magnesium alloy is composed of elements of Mg, Zn, rare earths, Nb, Al and Li, and comprises, by weight, 0.2 to 9 percents of Zn, 0.0002 to 2 percents of Zr, 0.0002 to 16 percents of rare earths, 0.0002 to 4 percents of Nb, 0.001 to 1.49 percents of Al, 0.0002 to 9 percents of Li, and the balance Mg. According to the magnesium alloy, the structure of Beta phase is changed by adding rare earth elements and the Nb element into the magnesium alloy; grains are refined by adding the Li and Zr elements; and the crystallization latent heat is changed when the magnesium alloy is solidified by the combined action of the elements, so that the heat resistant magnesium alloy which has good mold-filling capacities, low shrinkage rate, good mechanical properties, machinability, mobility and die-casting properties and is suitable for casting is obtained.