The magnetic and structural properties of MnAs are studied with ab initio methods and by mapping total energies onto a Heisenberg model. The stability of the different phases is found to depend mainly on the volume and on the amount of magnetic order, confirming previous experimental findings and phenomenological models. It is generally found that for large lattice constants the ferromagnetic state is favored, whereas for small lattice constants different antiferromagnetic states can be stabilized. In the ferromagnetic state the structure with minimal energy is always hexagonal, whereas it becomes orthorhombically distorted if there is an antiferromagnetic alignment of the magnetic moments in the hexagonal plane. For the paramagnetic state the stable cell is found to be orthorhombic up to a critical lattice constant of about 3.7 Å, above which it remains hexagonal. This leads to the second-order structural phase transition between paramagnetic states at about 400 K, where the lattice parameter increases above this critical value with rising temperature due to the thermal expansion. We also evaluate the magnetic susceptibility as a function of temperature, from which a semiquantitative description of the MnAs phase diagram emerges.