The technique makes use of the fact that biological systems are composed primarily of water.
Water contains hydrogen, which is just an electron orbiting a proton.
Protons have associated with them a quantity called spin. Because of this, we can think of the proton as a tiny spinning top. Protons, however,are also electrically charged. When something with an electrical charge is allowed to spin, it will have associated with it a magnetic moment. These magnetic moments can be thought of as little bar magnets.