Inter Milan survived a dramatic end to its Serie A campaign on Sunday to secure a Champions League spot for next season, while Atalanta will make its debut in Europe’s top club competition.

Leading 2-1 in the 89th minute against an Empoli team fighting relegation, Inter’s defense was in disarray as Danilo D’Ambrosio knocked an Empoli cross against his own crossbar, and soon after Inter goalkeeper Samir Handanovic was forced into a vital save.

When Empoli’s goalkeeper went up for a corner and Inter counterattacked, Marcelo Brozovic scored from the halfway line into an empty net and Inter seemed secure. But more drama was to come as the video assistant referee ruled the goal out because Empoli’s keeper was fouled as he hurried back to his goal and had Keita Balde, the scorer of Inter’s first goal sent off.

Empoli charged forward again, forcing Hamdanovic to save a header in the eighth minute of injury time but Inter held on for a 2-1 win with the second goal from Radja Nainggolan to secure Champions League football for a second straight year.

Four teams had been fighting for the last two Italian Champions League spots on Sunday. All won their games as Atalanta took third and Inter fourth, but none had it easy. Atalanta went a goal down to Sassuolo early on but fought back to win 3-1 after Sassuolo had Domenico Berardi sent off for his part in a brawl.

AC Milan fluttered in and out of fourth position throughout the evening thanks to goals elsewhere and its struggles with SPAL in a 3-2 win sealed by two goals from Franck Kessie. However, Inter’s tenacity and Atalanta’s comeback meant that Milan had to settle for fifth a point behind Inter and Atalanta and the Europa League.

Roma finished in sixth. It had started the day an outside contender and stayed that way despite an 89th-minute goal from Diego Perotti securing a 2-1 win over Parma. That marked the 616th and last appearance in a Roma shirt for midfielder Daniele de Rossi, who leaves the club after 18 seasons.

Next season Roma will be out of the Champions League for the first time since 2013-14, while Milan’s wait to return to the Champions League enters a sixth season. Further back, Torino beat Lazio 3-1 to secure seventh.