Nuclear magnetic resonance (NMR) in liquids and solids is primarily detected by recording the net dipolar magnetic field outside the spin-polarized sample. But the recorded bulk magnetic field itself provides only limited spatial or structural information about the sample. Most NMR applications rely therefore on more elaborate techniques such as magnetic field gradient encoding1 or spin correlation spectroscopy2, which enable spatially resolved imaging and molecular structure analysis, respectively. Here we demonstrate a fundamentally different and intrinsically information-richer modality of detecting NMR, based on the rotation of the polarization of a laser beam by the nuclear spins in a liquid sample. Optical NMR detection has in fact a long history in atomic vapours with narrow resonance lines3,4, but has so far only been applied to highly specialized condensed matter systems such as quantum dots5. It has been predicted6 that laser illumination can shift NMR frequencies and thus aid detection, but the effect is very small and has never been observed. In contrast, our measurements on water and liquid 129Xe show that the complementary effect—the rotation of light polarization by nuclear spins—is readily measurable, and that it is enhanced dramatically in samples containing heavy nuclei. This approach to optical NMR detection should allow correlated optical and NMR spectroscopy on complex molecules, and continuous two-dimensional imaging of nuclear magnetization with spatial resolution limited only by light diffraction.