A precise measurement of the g factor of the first-excited state in the self-conjugate (N=Z) nucleus (24)Mg is performed by a new time-differential recoil-in-vacuum method based on the hyperfine field of hydrogenlike ions. Theory predicts that the g factors of such states, in which protons and neutrons occupy the same orbits, should depart from 0.5 by a few percent due to configuration mixing and meson-exchange effects. The experimental result, g=0.538±0.013, is in excellent agreement with recent shell-model calculations and shows a departure from 0.5 by almost 3 standard deviations, thus achieving, for the first time, the precision and accuracy needed to test theory. Proof of the new method opens the way for wide applications including measurements of the magnetism of excited states of exotic nuclei produced as radioactive beams.