Die Mannschaft were six minutes away from crashing out of the UEFA EURO 2020 competition, but Leon Goretzka's goal saved them.
Germany's UEFA EURO 2020 hopes were in jeopardy until six minutes from time, when Leon Goretzka's goal rescued Joachim Low's team and put an end to Hungary's ambitious effort to advance from Group F.
Germany's fluency was subdued by heavy rain in Munich, and they trailed after 11 minutes.
Hungary were very fast on the counter, and Ádam Szalai put them ahead by throwing himself at Roland Sallai's brilliant cross from the right.
Mats Hummels headed against the crossbar from a Joshua Kimmich corner, and Matthias Ginter subsequently sent a close-range shot straight at Péter Gulacsi.
Hungary, on the other hand, appeared to have survived the storm, with Sallai slamming a free-kick against Manuel Neuer's post shortly after the hour.
After Gulacsi failed to pick out a Kimmich free-kick, Hummels nodded the ball on for Kai Havertz to head home from close range, bringing relief to Germany.
Within 16 seconds of the restart, they were behind again, with András Schäfer following down Szalai's ball and flicking it past Neuer.
Germany's situation appeared to be hopeless until Jamal Musiala dragged the ball back for Goretzka to tee up Timo Werner whose shot was blocked before it dropped for Goretza to slot in beyond Gulasci for the equaliser.
Man of the Match: Joshua Kimmich (Germany)
What the players and managers said
Roland Sallai, Hungary forward: "I'm very proud that we performed the way we did, but I’m disappointed at falling short. We’ve played ever so well. We can’t complain; we’re proud of how we’ve played. I think we’re on a really good path. We’ve made it very difficult for three exceedingly tough opponents."
Péter Gulácsi, Hungary goalkeeper: "We were under pressure, but we restricted Germany to very few chances. We reacted superbly after their first equaliser. We were so close. From the very start, we’ve focused on ourselves rather than our opponents. We’ve played three tight matches, and I’m disappointed that we haven’t gone through."
Joshua Kimmich, Germany wing-back: "Hungary were so compact and did very well. We were not great at finding a solution to the problem, but we showed great morale. In the end it is only important to go through. That will also be the case for the next match and I think we have a good chance to accomplish this."
Joachim Löw, Germany coach: "All the 'small' teams invest so much work and defend well. Hungary played with ten men in their own half and they had nothing to lose. It's great that we got through in this tough group. Now we can look forward to a match against England."