An electric current creates a magnetic field, and a rotating magnet creates an electric current. Electricity and magnetism are so interrelated -- you can't have one without the other. Frequently the term "electromagnetic" field is used.
It appears that the electric currents found deep within the large molten Iron core of the Earth are primarily responsible for Earth's magnetic field. The core is a turbulent world unto itself, with its own cycle of "weather" that generates the electromagnetic field. The field itself radiates far out into space and is known as the Magnetosphere, or the Van Allen Belts, in honor of American scientist James Van Allen (1917-2006) who discovered them in 1958. These are important as they defect the charged high energy ions ejected from the Sun in the form of the Solar Wind, which would otherwise irradiate the Earth and interfere with biological processes.