First-principles calculations have been used to investigate the physical properties of magnetic shape memory alloys. We find that the martensitic instability of the high-temperature cubic phase in X2YZ (X=Fe, Co, Ni, Pd; Y=Mn, Fe, Co; Z=Al, Ga, Ge, In, Sn) is strongly influenced by the anomalous change of the electronic density of states during the martensitic transformation. The tetragonal martensitic phase is stabilized by a largely reduced density of Ni-3d states near the Fermi level in the minority-spin channel. The magnetic nature of the materials allows for manipulation of the material properties by external magnetic fields. The calculations show that sufficiently large fields can suppress the martensitic transformation in the magnetic shape memory alloy Ni2MnIn.