Earth is indeed a huge magnet.
The magnetic and electric nature of the earth is explained in the Dynamo Theory.
The hot liquid part(magma) and the core of the earth consists of iron and nickel in abundance. This induces electric field and thus produces , even a magnetic field due to which earth acts as a magnet.(Magnetic field can be produced from electricity as in the case of a Solenoid..)
Hope this helps you..!