Francesco Totti's free-kick gave AS Roma a thrilling 3-2 win at AC Milan on Sunday to seal the final Europa League spot and ruin Paolo Maldini's last home appearance before retirement.
Third-placed Milan will visit fourth-placed Fiorentina in the last game of the season next Sunday to decide who takes the final automatic Champions League spot.
Fiorentina equalised late on to draw 1-1 at Lecce and condemn the hosts to relegation while also sealing fourth spot and at least a Champions League qualifying round berth.
Fifth-placed Genoa, who won 3-2 at relegation-threatened Torino in a bad-tempered clash, are three points behind Fiorentina but have a worse head-to-head record so can not overtake them next weekend.
Juventus sealed their place in the Champions League proper after a 3-0 win in the scorching heat of Siena, where firemen sprayed fans with water to keep them cool.
Juve, in their first game under interim coach Ciro Ferrara following Claudio Ranieri's sacking, moved above Milan into second because of their better head-to-head record and also have the same advantage over Fiorentina, meaning they cannot be caught.
The Turin side triumphed thanks to a brace from previously out-of-form Alessandro Del Piero.
At the San Siro, Roma took the lead through John Arne Riise's fierce free-kick but Massimo Ambrosini scored on the rebound to equalise 15 minutes from time.
Jeremy Menez put Roma back infront and Ambrosini levelled again before being sent off for two yellows.
Totti then fired in five minutes from time to leave Milan coach Carlo Ancelotti's future still in the air with the club waiting to hear their Champions League fate before announcing if he will leave.
Maldini, who will play his final game before retirement in Florence, took a lap of honour around the San Siro after fulltime but one group of supporters unfurled a banner critical of the 40-year-old.
The rest of the Rossoneri fans waved special Maldini scarves while Roma players came back on the pitch at the end wearing T-shirts hailing the defender, who was making his 901st Milan appearance.
Inter Milan, crowned champions last weekend, lost 2-1 at Cagliari but Zlatan Ibrahomivic scored to join Bologna's Marco Di Vaio at the top of the Serie A scoring charts with 23 goals.
Bologna drew 0-0 at Chievo and will battle Torino for the final relegation spot next Sunday.
They are above their rivals because of their better head-to-head record and will stay up if they match Torino's result at Roma next Sunday when they host Catania, whose coach Walter Zenga has said he is leaving.