The youngster scored a superb solo effort to send the Bianconeri through to the Coppa Italia last four and deal Clarence Seedorf his first defeat as Rossoneri boss.
The substitute scored a superb solo effort late in the second period after Luis Muriel's penalty had equalized following Mario Balotelli's early opener.
Milan was lackluster for large spells and did little to threaten Udinese once it had surrendered the lead, meaning Clarence Seedorf was made to suffer his first defeat in charge of the club as the most viable route to European qualification came to a stuttering halt.
Balotelli lead the line for Milan ahead of Kaka, Robinho and Walter Birsa in support, while Muriel was handed a first start in two months following injury in place of Antonio Di Natale for the visiting side.
It did not take long for Milan to seize the initiative. A lightning-quick counterattack allowed Birsa to drill in a cross, and Robinho's clever dummy at the near post allowed Balotelli to tap home from close range.
Birsa then tested Brkic with a free kick before Nigel de Jong hit an effort on target from distance, but Milan's control began to wane as Udinese grew into the game.
The lively Bruno Fernandes was denied at close range by Christian Abbiati after De Jong gave the ball away in the middle, and Badu came close as he surged into the box only to be denied at the near post.
The visiting side continued to impress and got the equalizer just before the break. Silvan Widmer was clumsily brought down by Urby Emanuelson inside the area, allowing Muriel to dispatch his effort low past Abbiati, who got a hand to the ball.
The second half was a far scrappier affair, with Muriel firing over from distance before Kaka did likewise for the home side.
Substitute Roberto Pereyra then scuffed an effort over the bar, before Balotelli tested Brkic from distance. The Italy striker then tested the Serbian from the edge of the box with a fierce free kick.
Pereyra then miscued when free in the area before Muriel did the same from the rebound as both sides tried to find a breakthrough - and it was substitute Lopez who did just that.
Udinese cleared after Robinho's run towards goal and Lopez burst clear into the Milan half before cutting towards the center and rifling a shot into the bottom corner.
A deflated Milan made a late salvo as the club tried to find an equalizer, but Udinese comfortably saw out the win to see the team safely into the last four to face either Fiorentina or Siena.