The corrosion of AZ91 magnesium alloy with residual stress was observed in-situ in an atmosphere of water vapor with cyclic wet-dry conditions using environmental scanning electron microscope (ESEM). The results showed that the oxygen concentration on the surface generally increased with the wetting time. And the average corrosion rate of AZ91 alloy with residual stress (RS) was much larger than that without RS, indicating RS accelerated corrosion. The corrosion localized at primary α-Mg area at short wetting time, but with the increase of wetting time spread to the eutectic α-Mg region. Small-size as-cast defects (<50μm) contributed little to the average corrosion rate while large-size as-cast defects (>100μm) influenced the distribution of water film and corrosion on the surface.