The in-form Stephan El Shaarawy gave Milan the lead in the 47th minute before Mexes doubled the advantage in the 72nd minute with his magnificent effort which rivalled former club-mate Zlatan Ibrahimovic's recent effort for Sweden against England for pure audacity.
The free-kick that led to Mexes' goal also saw Anderlecht lose Bram Nuytinck to a red card as Milan took a complete stranglehold on the match.
Anderlecht, who would have moved above Milan into second place in Group C with a win, pulled a goal back through substitute Tom De Sutter but they could not get back on level terms and Alexandre Pato sealed the Italian side's triumph and spot in the last 16 with a stoppage-time third.
The Belgian side, who must now battle it out with Zenit St Petersburg for a place in the Europa League, had the best chance of a closely-fought first half but Milan Jovanovic saw his 12th-minute effort saved by the feet of visiting goalkeeper Christian Abbiati.
Milan did not produce much to worry Anderlecht keeper Silvio Proto in the first period but they needed just two minutes of the second half to create a clear-cut chance, and El Shaarawy made the most of it.
The 20-year-old coolly brought down a deep cross that had just cleared the head of Anderlecht defender Cheikhou Kouyate and then curled a right-footed shot into the far side of the net from the edge of the six-yard box.
That was El Shaarawy's 13th goal in his last 16 appearances for club and country, but it was Mexes' goal that really took the breath away.
Nuytinck's professional foul on substitute Pato proved doubly costly, as not only did it result in him receiving a red card as last man, but from the resulting free-kick Mexes scored his wonder goal.
Riccardo Montolivo's ball in from deep was chested up into the air on the edge of the area by Mexes before the Frenchman sent an acrobatic looping overhead kick into the far top corner of the net with Proto rooted to his line.
De Sutter gave Anderlecht renewed hope when he pulled a goal back in the 79th minute with a close-range finish, but aside from a Olivier Deschacht effort they could not create much to worry Abbiati before Pato made it 3-1 late on following an El Shaarawy pass.