The ground-state spins and magnetic moments of neutron-rich Mg-27, Mg-29, and Mg-31 were measured for the first time with laser and beta-NMR spectroscopy at ISOLDE/CERN. The hyperfine structure of Mg-27 observed in fluorescence-confirms previous assignments of the spin I = 1/2 and reveals the magnetic moment mu(I) (Mg-27) = -0.4107(15) mu(N). The hyperfine structure and nuclear magnetic resonance of optically polarized Mg-29-observed in the asymmetry of its beta decay after implantation in a cubic crystal-give I = 3/2 and mu(I) (Mg-29) = +0.9780(6) mu(N). For Mg-31 they yield together I = 1/2 and mu(I) (Mg-31) = -0.88355(15) mu(N), where the negative magnetic moment provides evidence for a positive parity. The results for 27Mg and 29Mg agree well with shell-model calculations confined only to the sd model space, whereas the ground state of Mg-31 involves large contributions from neutrons in the pf shell, which places this nucleus inside the "island of inversion.".