Inter came from behind to snatch the final Champions League place in their winner-takes-all clash at Lazio in Serie A on Sunday.
The home side, who only needed to draw, were leading 2-1 at half-time after Adam Marusic and Felipe Anderson had scored either side of a Danilo Dâ€™Ambrosio effort.
But the game changed when Stefan de Vrij â€“ who has reportedly agreed on a move to Inter for next season â€“ gave away a penalty from which Mauro Icardi levelled.
Senad Lulic was sent off for a second booking shortly afterwards and Matias Vecino headed home from a corner with less than 10 minutes remaining to seal a remarkable 3-2 victory.
There had been drama shortly before Icardiâ€™s equaliser when Inter were awarded a penalty for a push by Marusic, only for the Video Assistant Referee to overturn the decision.
Victory moved Inter level on points with Lazio, who had a significantly better goal difference, but head-to-head records are used in Serie A meaning Luciano Spallettiâ€™s men finished fourth.
Lazioâ€™s fierce rivalsÂ RomaÂ ended their campaign with a narrow 1-0 win atÂ Sassuolo.Â The only goal of the game came in the closing seconds of the first half when defender Kostas Manolasâ€™ attempted cross somehow crept in.
SPAL and Cagliari saved themselves from the possibility of relegation with final-day victories, meaning a return to Serie B for Crotone.
CrotoneÂ had to win to have any chance of survival and then hope other results went their way, but neither permutation materialised.
Goals from Arkadiusz Milik and Jose Callejon put second-placedÂ NapoliÂ in control against them before Marco Tumminelloâ€™s late reply for the Calabrian side.
Two goals from Mirco Antenucci and another by Alberto Grassi sawÂ SPALÂ take command againstÂ Sampdoria, helped by a red card for visiting forward Gianluca Caprari. Dawid Kownacki pulled one back but SPAL ran out 3-1 winners.
Luca Ceppitelli struck three minutes from time asÂ CagliariÂ defeatedÂ Atalanta, who still finished seventh and qualified for the Europa League asÂ FiorentinaÂ were thrashed 5-1 byÂ AC MilanÂ at the San Siro.
Milan wrapped up a Europa League group stage place at the end of Gennaro Gattusoâ€™s first season in charge. Hakan Calhanoglu quickly equalised after Giovanni Simeoneâ€™s 20th-minute opener before further goals from Patrick Cutrone (2), Nikola Kalinic and Giacomo Bonaventura.
Elsewhere, Seko Fofanaâ€™s strike gaveÂ UdineseÂ a 1-0 home win againstÂ BolognaÂ andÂ ChievoÂ beat bottom clubÂ BeneventoÂ by the same scoreline courtesy of Roberto Ingleseâ€™s goal.
TorinoÂ won 2-1 atÂ GenoaÂ thanks to goals from Iago Falque and Daniele Baselli, although they finished the match a man down when Cristian Ansaldi was sent off shortly after Goran Pandevâ€™s 80th-minute reply.