Two goals in the final six minutes earned AC Milan a crucial final-day win at Siena and a place in next season's Champions League.
The Rossoneri, who needed to win to secure a top-three finish in Serie A on account of Fiorentina's big victory at Pescara, fell behind on 25 minutes.
Claudio Terzi headed home from very close range following a pinpoint Alessandro Rosina free kick.
Both sides were reduced to 10 men midway through the second half, as Christian Terlizzi and Massimo Ambrosini were sent off for collecting second yellow cards.
Milan responded better to the numerical upheaval and levelled on 84 minutes, when Mario Balotelli converted a penalty kick after being fouled by Felipe.
The turnaround was complete three minutes later, as Philippe Mexes bundled the ball beyond goalkeeper Gianluca Pegolo.
Relegated Siena finish 19th after losing their last six matches.