Hungary qualified for Euro 2024 when a Bulgarian own goal late in stoppage time gave them a 2-2 draw in Sofia on Thursday.
The Hungarians needed a single point to clinch their ticket to the finals in Germany but were trailing 2-1 before Alex Petkov headed 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.
However Bulgarian fans protesting against their own football federation clashed with police outside the ground.
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 largely directed 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.
But just as it seemed Hungary were slipping to defeat, the unfortunate Petkov headed a Hungarian cross into his own net.