Antonio Di Natale fired Udinese in front after 17 minutes when he exchanged passes with Gelson Fernandes and took a shot at goal that redirected off Milan's Thiago Silva before beating goalkeeper Marco Amelia.
The hosts had chances to extend their lead but were punished in the 77th minute on the counter attack as Stephan El Shaarawy's shot was saved by goalkeeper Samir Handanovic, only for Maxi Lopez to follow up the rebound and score his first goal for Milan.
El Shaarawy was taking the place of the suspended Zlatan Ibrahimovic and he made the most of his opportunity by scoring the winner five minutes from time.
Lopez played provider on the goal for the 19-year-old El Shaarawy, who turned his shot past Handanovic from seven yards to claim three vital points for Milan.
Udinese remains in fourth having lost for the third time in four games.
Cagliari, Italy - Palermo's good run of form came to an end on Saturday at Cagliari as the hosts held on for a 2-1 win that moves them into the top half of the league.
Cagliari's Segundo Ibarbo beat Palermo goalkeeper Emiliano Viviano to the ball and he squared it to Mauricio Pinilla for a simple tap in to give the hosts the lead in the 56th minute.
Daniele Dessena doubled the advantage nine minutes from time when Pinilla's free kick was parried into his path by the 'keeper, allowing Dessena to slam home his first goal of the season.
Palermo came right back and scored two minutes later as a shot from Abel Hernandez was handled inside the penalty area, giving Hernandez the chance to beat goalkeeper Michael Agazzi from the spot.
But the hosts held out for all three points, snapping Palermo's four-game unbeaten run.