This is because the Earth also behaves like a magnet. The magnetic south pole of the Earth is located near the geographic north pole of the Earth. As we already know that unlike poles attract each other, the north pole of the magnetic needle gets attracted towards the magnetic south pole of the Earth i.e., the geographic north pole.