The visitors went into the match knowing that they simply needed to avoid defeat against Group G's bottom side in order to secure their place at next summer's tournament in Germany.
However, it looked as though they may be forced to wait a little longer when Kiril Despodov put Bulgaria 2-1 ahead from the penalty spot with only 11 minutes of normal time remaining.
Hungary captain and Liverpool midfielder Dominik Szoboszlai led the charge in search of an equaliser, though, and his free kick in the seventh minute of added time was inadvertently flicked home by Alex Petkov for an own goal which sparked wild scenes of celebrations amongst the Hungarian players and staff.
It was not a moment that their fans could share inside the stadium after a remarkable late ruling caused the venue to be switched from Plovdiv to Sofia just two days before the match, with the Bulgarian FA then making an unprecedented request for their home match to be held behind closed doors - something UEFA allowed.
The decision contributed to violent protests by supporters outside the ground before the match as home fans demonstrated against the head of the Bulgarian Football Union Borislav Mihaylov, with riot police being called in to quell the unrest.
There were disciplinary problems on the field too, with both sides being reduced to 10 men for two bookable offences, Valentin Antov seeing red for the hosts before half time and Bournemouth's Milos Kerkez given his marching orders for Hungary after the interval.
By that stage it was already 1-1 after Spas Delev had cancelled out Martin Adam's opener, which Szoboszlai also assisted before having a hand in the late drama.
The result sees Hungary become the first team to qualify from Group G, although they could be joined by Serbia this evening if Montenegro fail to beat Lithuania.
The Magyars have now reached each of the last three European Championships, after missing out on 10 in a row before that.