Spinning compass

By pulsing the connection to the battery we can cause a compass to spin. How is this working?

License: CC BY-NC-SA by Khan Academy