The Earth’s molten iron core creates a magnetic field:
The Earth is like a great big magnet, with poles at the top and bottom of the planet, near to the actual geographic poles. This magnetic field extends thousands of kilometers out from the surface of the Earth – forming a region called the magnetosphere.