Fiorentina: Frey; De Silvestri, Kroldrup, Natali (Gobbi 46), Felipe; Montolivo, Donadel, Vargas; Marchionni, Jovetic (Zanetti 59); Gilardino (Keirrison 62)
Milan: Abbiati; Abate, Nesta, Thiago Silva, Bonera (Jankulovski 65); Gattuso (Huntelaar 76), Pirlo, Ambrosini (Flamini 32); Pato, Borriello, Ronaldinho
Alexandre Pato struck deep in stoppage time as AC Milan came from behind to snatch victory at Fiorentina on Wednesday.
The outcome has lifted the Rossoneri above Roma into second in Serie A and reduced the gap with league leaders Inter Milan to four points.
Former AC Milan striker Alberto Gilardino opened the scoring in the 14th minute before Klass Jan Huntelaar came off the bench to restore parity with nine minutes remaining.
AC Milan goalkeeper Christian Abbiati kept his team in the game with two great saves before Pato silenced the fans at the Artemio Franchi stadium seconds from time.
England midfielder David Beckham dropped to the bench for the second league game in a row as Leonardo opted to field the same starting XI that won 2-0 at Bari on Sunday.
The visitors struggled in the opening half but showed plenty of determination to turn around the result in the last ten minutes of the game.
The Rossoneri should have broken the deadlock early on but Andrea Pirlo's goal-bound strike was deflected by Riccardo Montolivo for a corner. At the other end, Gilardino latched onto Juan Vargas' cross but his central header did not trouble Abbiati.
The hosts broke the deadlock shortly after as Milan's defence failed to clear Stevan Jovetic's pass towards the area, leaving Gilardino with an easy tap-in.
The visitors reacted and Frey was forced to punch away Ronaldinho's curled free-kick. Midway through the first half, though, Montolivo's right-footed strike from 25 yards forced Abbiati to fully stretch to clear.
Leonardo was forced to make his first substitution with Mathieu Flamini replacing injured captain Massimo Ambrosini.
Flamini almost levelled the scores before the break with his right-footed strike from the edge of the area going inches wide of the far post.
Milan picked up where they left off after the re-start and Pato almost scored shortly after. The Brazilian surged inside the area before firing just wide of the far post.
At the other end, Vargas' bullet strike from the distance was met by a fine save from Abbiati.
With 15 minutes remaining, Leonardo brought in Huntelaar in place of Gattuso and it proved to be the right move because the substitute equalised five minutes later as Huntelaar played a one-two with Ronaldinho before firing from the heart of the area past Frey.
Milan's joy could have shortlived had Abbiati not made an acrobatic clearance to palm over the bar Vargas' stinging drive from 25 yards.
The visitors continued to push forward and their efforts were rewarded with seconds remaining when Ronaldinho's cross found Pato inside the area and his right-footed strike towards the centre of the goal beat Frey .
Milan host Atalanta on Sunday while Fiorentina travel to Rome on Saturday to take on Lazio.