Leon Goretzka's late equaliser was enough for Germany to draw 2-2 with Hungary and secure the second spot in Group F, setting up a last-16 showdown with England.
Germany were hoping to follow up their 4-2 win against Portugal on Saturday with a comfortable victory against Group F underdogs Hungary, but made the worst possible start as Adam Szalai (11) nodded home.
The hosts were mostly laboured in their play but were handed a lifeline as Mats Hummels and Kai Havertz took advantage of an error from goalkeeper Peter Gulacsi, allowing the Chelsea forward (66) to nod home from close range.
But 91 seconds later and straight from the restart, Hungary re-took their precious lead. Adam Szalai set up Andras Schafer (68) to slot past Manuel Neuer, sending Germany to the bottom of Group F and on the verge of a second successive exit in the group stages of a major tournament.
There was more drama to come though as Goretzka fired home in the 84th minute to fire Germany into second place, setting up an enticing last-16 tie with old foes England at Wembley on Tuesday.
It was heartbreak for Hungary, who were minutes away from reaching the knockout rounds for a second European Championships.
It echoed their 3-3 draw against Portugal from Euro 2016 too, where they were pegged back three times during a thrilling encounter. However, in a tough group, they are able to exit Euro 202 with their heads held high.