It looked like Udinese coach Francesco Guidolin was going to celebrate his first ever victory against Milan after Antonio Di Natale gave the home team the lead in the 17th minute.
Udinese continued to dominate the game against an off-colour Milan, but Maxi Lopez equalised in the 77th minute and 19-year-old El Shaarawy scored eight minutes later.
The win lifted Milan two points above Juventus at the top of Serie A, but the Turin side have two games in hand.
Cagliari climbed into the top half of the table - up to ninth - thanks to a 2-1 win over Palermo at a deserted Stadio Sant Elia.
Mauricio Pinilla gave the home side the lead in the 56th minute, scoring against his former club, and Daniele Dessena doubled their advantage in the 81st minute.
A penalty from Abel Hernandez a minute later gave Palermo hope and the home team had to survive a late onslaught from the Rosaneri before earning the points in front of just a few thousand fans.
Two of Serie A's Sunday games have been called off by officials because of deteriorating weather conditions in Italy.
Juventus's match at Bologna and Fiorentina's trip to Parma have both been postponed.
Saturday's Serie A Results
Sunday's Serie A Fixtures
Parma vs Fiorentina - PP
Bologna vs Juventus - PP
Monday's Serie A Fixtures
Napoli vs Chievo
Siena vs Roma