Answer:
The magnetic field is generated by electric currents due to the motion of convection currents of molten iron in the Earth's outer core: these convection currents are caused by heat escaping from the core, a natural process called a geodynamo.