The two poles are northern and southern poles of a strong magnetic field. The compass, which is in fact a weak magnet and the iron rods that turn into magnets in a magnetic field, move according to the invisible construction of the magnetic field.

Our Earth has a magnetic field, too!
The compass is obeying this force when it turns into north-south direction.

The magnetic field of the Earth protects us from cosmic radiance, that is especially strong at solar flares. Without it there would not be any life on Earth.