  The stability of MgH$_2$ has been studied up to 20~GPa using
density-functional total-energy calculations. At ambient pressure
$\alpha$-MgH${_2}$ takes a TiO$_2$-rutile-type structure. $\alpha$-MgH$_2$ is
predicted to transform into $\gamma$-MgH${_2}$ at 0.39~GPa. The calculated
structural data for $\alpha$- and $\gamma$-MgH${_2}$ are in very good agreement
with experimental values. At equilibrium the energy difference between these
modifications is very small, and as a result both phases coexist in a certain
volume and pressure field. Above 3.84~GPa $\gamma$-MgH${_2}$ transforms into
$\beta$-MgH${_2}$; consistent with experimental findings. Two further
transformations have been identified at still higher pressure: i) $\beta$- to
$\delta$-MgH${_2}$ at 6.73 GPa and (ii) $\delta$- to $\epsilon$-MgH${_2}$ at
10.26~GPa.
