Earth began as a hot molten ball and still retains some of its original heat.
The rocks inside the earth contain radioactive atoms which eventually decay and this process gives off heat. Many of these rocks are isotopes of uranium, potassium, and thorium.
Heat is also generated by friction when huge rocks slide past each other.
As you move to the centre of the earth, the pressure increases (because of the huge amounts of rock pressing down on it).
The higher the pressure, the higher the melting point of substances.
This huge pressure at the surface means that the inner core does not melt or vaporize.
Because of this, the mantle gets harder as you move towards the inner core.
The earth has giant magnetic fields around it.
The earth is spinning on its axis and there is a heating effect from the centre. Both of these factors mean that liquid metal is in motion.
The moving electrons in the metal produce current which in turn produces the magnetic field.
The earths magnetic field is getting stronger and stronger because of this.