We report, for the first time, the atomic structure of amorphous MgO based on ab initio molecular dynamics simulations. We find that its main building blocks are four-fold and five-fold coordinated configurations, similar to those formed in the liquid state. Its average coordination is estimated to beabout 4.36. The amorphous form having a perfect stoichiometry has a band gap energy of 2.4eV. On the other hand, Mg vacancies induce an insulator to metal transition and ferromagnetism in amorphous MgO whilst O vacancies do not cause such a transition, implying that the magnetism in amorphous MgO is related to the non-stoichiometry and Mg vacancies. With the application of pressure, the stoichiometric and non-stoichiometric (Mg vacancies) models undergo a phase transformation into a rocksalt state, suggesting that the electronic structure of the initial configurations has no influence on the resulting high-pressure phase in amorphous MgO.