Mg (Z = 12) 1s2 2s2 2p6 3s2 .
Al (Z = 13) 1s2 2s2 2p6 3s2 3p1 .
Although the nuclear charge of aluminium is greater than that of magnesium, I.E of Mg is greater than that of Al. It is because Mg atom has more stable configuration than Al atom. IE1 of Mg > IE1 of Al.