Inter had to win in order to take third place from Lazio who had a superior head-to-head record and needed just to draw.
Late goals from captain Mauro Icardi and Matias Vecino ensured Inter return to Europe for the first time since the 2011-2012 season, along with Juventus, Napoli and Roma.
Lazio had led 2-1 with a quarter of an hour to go in Rome after Ivan Perisic turned the ball into his own net and Brazilian Anderson got a second four minutes before the break.
But Danilo D’Ambrosio got one back after 29 minutes with Icardi slotting in a penalty after 78 minutes following a Stefan De Vrij foul to join Lazio’s Ciro Immobile as the top Serie A scorer this season with 29 goals.
Lazio captain Senad Lulic was sent off late for a second yellow card with Vecino heading in the winner minutes later.
Both Inter and Lazio finished equal on 72 points but Inter are ahead on direct clashes leaving Lazio fourth, five points behind Roma who beat Sassuolo 1-0 on Sunday.
Lazio go into the Europa League along with AC Milan who sealed direct access to the group stage with a 5-1 rout of Fiorentina, who finish eighth.
Earlier second-placed Napoli ended their record-breaking season with a 2-1 win that condemned Crotone to second-tier football next season.
Lorenzo Insigne orchestrated both Napoli goals as the southerners achieved a club record 91 points for the season — four behind champions Juventus.
Juve lifted the Scudetto for the seventh consecutive year with a game to spare and capped the season with a 2-1 win over Verona on Saturday, during which goalkeeping star Gianluigi Buffon called time on his 17-year career with the Turin giants.
Maurizio Sarri’s Napoli also became the first Serie A side to reach 90 points and still not win the league.
Crotone return to Serie B after two seasons in the top flight where they join already-relegated Verona and Benevento.
Although their dream of a first Serie A title since 1990 was over, Sarri’s side were in attacking mood.
Napoli poured forward from the start with Insigne setting up Polish forward Arkadiusz Milik to head in after 23 minutes.
Forward Insigne, who has been called up by new Italy coach Roberto Mancini to the national side, then provided the assist for Jose Callejon’s second after 32 minutes.
Marco Tumminello pulled one back for the side from Calabria in injury time.
Patrick Cutrone scored a double as Milan went on a goal spree in a come-from-behind win over Fiorentina at the San Siro that sealed sixth place and direct access to the Europa League group stage.
Fiorentina took the lead on their first chance after 20 minutes with Federico Chiesa’s sliding pass picked up by Giovanni Simeone, who finished off over a helpless Gianluigi Donnarumma.
Three minutes later Milan were back on level terms with Turkish international Hakan Calhanoglu’s equaliser.
Cutrone headed in the first of his double four minutes before the break, and almost added a second before half-time but shot wide.
Croatian forward Nikola Kalinic extended Milan’s lead on 49 minutes off a rebound with Calhanoglu setting up Cutrone for his second 10 minutes later.
Cutrone thought he had completed a hat-trick with a header but was flagged offside.
Giacomo Bonaventura completed the rout after a run through midfield on 76 minutes.
Milan finished the season with 64 points while Fiorentina, whose season was devastated by the sudden death of captain Davide Astori in March, missed out on European action by finishing eighth.
Atalanta took seventh place and a spot in the Europa League qualifying rounds despite a 1-0 defeat at Cagliari after a late Luca Ceppitelli winner.
Earlier, Iago Falque and Daniele Baselli scored in either half to give 10-man Torino a 2-1 win at Genoa to finish ninth.
Promoted SPAL get to play another year in Serie A and capped the season with a 3-1 win over Sampdoria.