Although Mg alloy possesses high specific strength, low density, and good biocompatibility, poor corrosion resistance hinders its further applications. In the present study, an innovative protective layer against corrosion was prepared on the AZ31 Mg alloy via alkali pretreatment followed by vanillic acid treatment. The alkali pretreatment supplied –OH for the AZ31 Mg alloy surface to react with vanillic acid. The vanillic acid treatment played a crucial role in enhancing the corrosion resistance due to the excellent ability to act as a barrier and retard aqueous solution penetration, which effectively isolated the underlying Mg alloy from the corrosive environment. The corrosion current density of alkali and vanillic acid‐treated Mg alloy (AZ31V) almost showed two orders of magnitude lower values in comparison with that of the AZ31 Mg alloy, and the corrosion potential of AZ31V Mg alloy increased from −1.41 to −1.25 V. The immersion tests proved that there was no occurrence of severe corrosion. Hence, the alkali pretreatment and vanillic acid treatment may represent a promising method to improve the corrosion resistance of Mg alloy.