  Fe-bearing MgO [(Mg$_{1-x}$Fe$_x$)O] is considered a major constituent of
terrestrial exoplanets. Crystallizing in the B1 structure in the Earth's lower
mantle, (Mg$_{1-x}$Fe$_x$)O undergoes a high-spin ($S=2$) to low-spin ($S=0$)
transition at $\sim$45 GPa, accompanied by anomalous changes of this mineral's
physical properties, while the intermediate-spin ($S=1$) state has not been
observed. In this work, we investigate (Mg$_{1-x}$Fe$_x$)O ($x \leq 0.25$) up
to $1.8$ TPa via first-principles calculations. Our calculations indicate that
(Mg$_{1-x}$Fe$_x$)O undergoes a simultaneous structural and spin transition at
$\sim$0.6 TPa, from the B1 phase low-spin state to the B2 phase
intermediate-spin state, with Fe's total electron spin $S$ re-emerging from $0$
to $1$ at ultrahigh pressure. Upon further compression, an intermediate-to-low
spin transition occurs in the B2 phase. Depending on the Fe concentration
($x$), metal$-$insulator transition and rhombohedral distortions can also occur
in the B2 phase. These results suggest that Fe and spin transition may affect
planetary interiors over a vast pressure range.
