On moving from left to right in a period, the ionization energy increases.
Al has lower ionization energy than Mg. Al has valence shell electronic configuration $3 s^{2} 3 p^{1}$.
Mg has valence shell electronic configuration $3 s^{2}$.
Less energy is required to remove a p electron than filled s electron from the same principal quantum shell.