The influence of heat treatment of magnesium alloy substrates on corrosion resistance of a sol-gel coating has been assessed during immersion tests in 0.6 M NaCl aqueous solution. Relative differences in the chemical nature of the layers were quantified by scanning electron microscopy (SEM) and energy dispersive analysis of X-ray (EDX). Corrosion behaviour was evaluated by Electrochemical Impedance Spectroscopy (EIS) and hydrogen evolution measurement. Long-term immersion testing show that the sol-gel/heat treated AZ61 substrate exhibits a superior anti-corrosion property in comparison with the sol-gel/non-heated substrate. In contrast, no significant changes have been observed between the heated and non-heated samples in the case of the sol-gel coated AZ31 substrates. A link was found between lower O/Si atomic ratios observed by EDX analysis on the sol-gel coatings after the preparation process and reduced corrosion upon the coated substrates. Heat-treatment increased the protective properties of the passive film on the surface of the AZ61 substrate and hence inhibited magnesium dissolution and hydrophilic group formation during coating preparation.