Dynamic nuclear polarization, which transfers the spin polarization of electrons to nuclei, is routinely applied to enhance the sensitivity of nuclear magnetic resonance. This method is particularly useful when spin hyperpolarization can be produced and controlled optically or electrically. Here we show complete polarization of nuclei located near optically polarized nitrogen-vacancy centres in diamond. Close to the ground-state level anti-crossing condition of the nitrogen-vacancy electron spins, 13 C nuclei in the first shell are polarized in a pattern that depends sensitively upon the magnetic field. Based on the anisotropy of the hyperfine coupling and of the optical polarization mechanism, we predict and observe a reversal of the nuclear spin polarization with only a few millitesla change in the magnetic field. This method of magnetic control of high nuclear polarization at room temperature can be applied in sensitivity enhanced nuclear magnetic resonance of bulk nuclei, nuclear-based spintronics, and quantum computation in diamond.