Magnetic torque on
If two like poles of two separate magnets are brought near each other and one of the magnets is allowed to turn it will promptly rotate to align itself with the first. In this example, the magnetic field of the stationary magnet creates a magnetic torque on the magnet that is free to rotate. This magnetic torque τ tends to align a magnet's poles with the magnetic field lines. A compass, therefore, will turn to align itself with earth's magnetic field.