The action mechanism of uric acid, C5H4N4O3 (UA), and the effect of its concentration (0, 100, 416 and 500 mu M) on the corrosion behavior of AZ31 Mg alloy in simulated body fluid were unmasked using scanning electron microscopy, x-ray diffraction, Raman, x-ray photoelectron spectroscopy, electrochemical impedance spectroscopy, potentiostatic polarization, potentiodynamic polarization, and hydrogen evolution tests. It was shown that UA was initially dissociated into (C5H4N4O3)- (UA-) and precipitated as (C5H4N4O3)2Mg ((UA-)2Mg). With the generation of (UA-)2Mg, hydroxyapatite (HA) was continuously formed, enhancing the corrosion resistance of AZ31 Mg alloy. Subsequently, UA- was transformed into C5H2N4O3 and chelated with Ca in HA as Ca(C5H2N4O3), resulting in a loss of HA and undermining the corrosion resistance of AZ31 Mg alloy. UA inhibited the corrosion of AZ31 Mg alloy with an optimal concentration of 416 mu M. The inhibition of UA on the corrosion of AZ31 Mg alloy was closely related with the content of (UA-)2 Mg, Mg3(PO4)2, and Mg(OH)2 in the corrosion products.