Abstract : Terrestrial core formation occurred in the early molten Earth by gravitational segregation of immiscible metal and silicate melts, stripping iron-loving elements from the silicate mantle to the metallic core1-3, and leaving rock-loving components behind. Here we performed experiments showing that at high enough temperature, Earth's major rock-loving component, magnesium oxide, can also dissolve in core-forming metallic melts. Our data clearly point to a dissolution reaction, and are in agreement with recent DFT calculations. Using core formation models5, we further show that a high-temperature event during Earth's accretion (such as the Moon-forming giant impact) can contribute significant amounts of magnesium to the early core. As it subsequently cools, the ensuing exsolution of buoyant magnesium oxide generates a substantial amount of gravitational energy. This energy is comparable to if not significantly higher than that produced by inner core solidification - the primary driver of the Earth's current magnetic field1. Since the inner core is too young to explain the existence of an ancient field prior to ~1 billion years, our results solve the conundrum posed by the recent paleomagnetic observation of an ancient field at least 3.45 Gyr old.