Rocky planets are thought to comprise compounds of Mg and O as these are among the most abundant elements, but knowledge of their stable phases may be incomplete. MgO is known to be remarkably stable to very high pressure and chemically inert under reduced condition of the Earth's lower mantle. However, in exoplanets oxygen may be a more abundant constituent. Here, using synchrotron x-ray diffraction in laser-heated diamond anvil cells, we show that MgO and oxygen react at pressures above 96 GPa and T = 2150 K with the formation of I4/mcm MgO2. Raman spectroscopy detects the presence of a peroxide ion (O2(2-)) in the synthesized material as well as in the recovered specimen. Likewise, energy-dispersive x-ray spectroscopy confirms that the recovered sample has higher oxygen content than pure MgO. Our finding suggests that MgO2 may be present together or instead of MgO in rocky mantles and rocky planetary cores under highly oxidized conditions.