We do not know for sure. Magnetic fields have been shown to affect the motion of many animals. In some cases, as in magnetotactic bacteria, the animal contains a significant volume of a magnetized magnetic compound such as iron oxide, rather like an internal compass, and the action of a magnetic field on those magnetic particles produces a force or torque that can affect the animal's motion. Similar but less pronounced effects have been observed in larger animals, but the mechanism has yet to be determined.
making a small donation to science.ca.