AZ31 magnesium alloy with different annealing temperatures was subjected to micro-arc oxidation (MAO) treatment, and its corrosion behaviour was studied using immersion experiments, polarisation curves, electrochemical impedance spectra, scanning electron microscopy (SEM) and X-ray diffraction (XRD) spectra. The alloy, when annealed at 300 °C, had the smallest grain size and the lowest electrical conductivity. Compared to other annealed alloys, the MAO coating had the smallest pore size and porosity and better corrosion resistance. The corrosion resistance of the alloy increased initially and then decreased with the increase in annealing temperature. This is mainly because the grain size first decreases and then increases, leading to a decline in electrical conductivity and then a rise, resulting in changes in the microstructure of the coating surface.