The earth acts as a giant magnet.
Compasses point north because the Earth is basically a giant magnet.