We investigate the structural stability and magnetic properties of the cubic, tetragonal and hexagonal phases of Mn3Z (Z=Ga, Sn and Ge) Heusler compounds using first-principles density-functional theory. We propose that the cubic phase plays an important role as an intermediate state in the phase transition from the hexagonal to the tetragonal phases. Consequently, Mn3Ga and Mn3Ge behave differently from Mn3Sn, because the relative energies of the cubic and hexagonal phases are different. This result agrees with experimental observations for these three compounds. The weak ferromagnetism of the hexagonal phase and the perpendicular magnetocrystalline anisotropy of the tetragonal phase obtained in our calculations are also consistent with experiment. © 2013 IOP Publishing Ltd.