Hungary clinched their ticket for Euro 2024 on Thursday thanks to an own goal from Bulgaria's Alex Petkov deep in stoppage time, which gave the Hungarians a 2-2 draw in Sofia.
The visitors only needed a point to qualify for the finals in Germany but were 2-1 down before Petkov allowed a cross to skid off the top of his head and into his own net in the 97th minute.
The Hungarian players exploded in joy at the end of a match played in an empty stadium because of fears of violence.
Ten Bulgarian fans protesting against their own football federation and five police were hurt in clashes outside the national stadium. Police also used water cannon.
The draw gave Hungary 15 points from seven games in Group G of European qualifying, two ahead of Serbia.
The Hungarians join host nation Germany, Austria, Belgium, England, France, Portugal, Scotland, Spain and Turkey as the teams qualified so far for next year's finals.
Hungary, whose play was orchestrated by Liverpool midfielder Dominik Szoboszlai, took the lead in the 10th minute through Martin Adam but Spas Delev pulled Bulgaria level on 24 minutes.
Bulgaria grabbed the advantage in a hard-fought game when Kiril Despodov placed a penalty beyond the outstretched hand of the Hungarian 'keeper after Despodov had been fouled by Attila Szalai.
Just as it seemed Hungary were slipping to defeat, the unfortunate Petkov headed into his own net.
In other early games, Spain, who have also already booked their ticket, were comfortable 3-1 winners in Cyprus as 16-year-old Barcelona starlet Lamine Yamal scored first for the Spanish in the fifth minute.
Yamal had become Spain's youngest player and scorer in a 7-1 qualifying win against Georgia in September and on Thursday he rounded the goalkeeper and smashed home the opener.
Already-qualified Scotland came from behind to draw 2-2 with Georgia in Tbilisi thanks to Lawrence Shankland's 93rd minute equaliser.
Azerbaijan thrashed a woeful Sweden 3-0 in Baku in Group F, from which Austria and Belgium have already qualified. Austria beat bottom team Estonia 2-0.