Due to the continuous flow of molten magma and lava inside the earth, there is the magnetic field of the earth as if there is a huge bar magnet inside the earth along its axis little different from geographic axis.
The earth's magnet has it north pole towards the geographic south and vice versa.The magnet has the bar magnet suspended is affected by this field and hence shows the N-S direction.