Milan fell a goal behind to Claudio Terzi (25) and it remained that way until six minutes from time when Mario Balotelli levelled from the penalty spot.
Yet with Fiorentina hammering Pescara 5-1, Milan needed another goal to finish third in Serie A and take the final Champions League berth, and they duly got the job done with three minutes remaining as Philippe Mexes fired home.
Both teams finished the match with 10 men after Milan captain Massimo Ambrosini and Siena's Christian Terlizzi were sent off for second yellows in the second half.
Fiorentina were a class above relegated Pescara in their encounter but at the end of the night were hugely disappointed to come away with a place in the Europa League as their reward.
Vincenzo Montella's side won with ease thanks to a hat-trick from Adem Ljajic and goals from Steven Jovetic and Matias Fernandez.
Udinese made no mistake in tying down the final automatic Europa League place by condemning Inter Milan to a 5-2 defeat at the San Siro.
Lazio must pursue Europa League football via the Coppa Italia final after a 1-0 defeat at Cagliari. Daniele Dessena claimed all three points with a late header.
Walter Mazzarri lost to the club who could well offer him his next job in management as Roma beat league runners-up Napoli 2-1.
Mazzarri revealed after the defeat that he was leaving Napoli after four years, with Roma, Milan and Inter all touted a potential destinations.
Sunday night's clash was settled by second-half goals from Marquinho and Mattia Destro, while Napoli replied through Edinson Cavani.
Palermo suffered a 3-1 home defeat to Parma in their final outing ahead of their relegation to Serie B.
A late goal from Cyril Thereau denied Atalanta a winning end to the season as Chievo took home a point from a 2-2 draw.
Bologna and Genoa played out a goalless stalemate while Torino and Catania drew 2-2.