This is an oxidation-reduction (redox) reaction:
2 Mg0 - 4 e- → 2 MgII
(oxidation)
2 O0 + 4 e- → 2 O-II
(reduction)