This is my understanding of it:
So for the corrosion of an iron pipe for instance the following occurs: 2Fe(s) -> 2Fe2+(aq) + 4e-
These electrons are forming iron hydroxides: O2 + 2H2O +4e- -> 4OH-
Applying a voltage causes the water to lose electrons at the inert anode: 2H2O -> O2 + 4H+ +4e-
and these electrons are used to convert the iron ions back into iron: 2Fe2(aq) + 4e- -> 2Fe(s)