The 34-year-old Hungary captain, who will end his international career after their last League A-Group 3 game against Italy on Monday, raced to the near post and flicked the ball into the net with his heel from a corner in the 17th minute to leave goalkeeper Marc Andre ter Stegen frozen on the spot.
Hungary, who also beat England 4-0 away in June for the hosts worst home defeat for 94 years, are top of the group on 10 points with Italy second on eight after beating England 1-0.
The Germans, in third place on six points, suffered their first defeat under coach Hansi Flick in their penultimate game before the World Cup in November, and can no longer qualify for the Nations League final four. England are bottom on two.
Germany were on the back foot from the start and ter Stegen, starting in the absence of Manuel Neuer who has tested positive for COVID-19, had to rescue them in the 25th when he stopped Daniel Gazdag‘s effort from close range.
Lacking any energy and posing no real threat, the hosts had to wait 27 minutes before firing a shot towards the Hungary goal, with Leroy Sane‘s long-range effort flying high over Peter Gulacsi‘s crossbar.
Sane did better in the 51st but Gulacsi denied the Germany forward. The home side were sharper after the break and had lots of possession but carved out far too few chances with lone striker Timo Werner taken off after 69 minutes.