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.
"Adam Szalai really deserves all the praise," said Hungary's Italian coach Marco Rossi. "In the first half we performed well, in the second we had to defend very deep.
"We can crown it all in the match against the Italians. It will be a special match for me against Italy. We are happy that we got 10 points from five matches. No one believed that."
Germany, 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.
More importantly, for the coach, it was a reminder that his players still need to improve in the two months leading up to the tournament.
"The team just got a wake-up call. It is better to be frustrated to lose today and not top the Nations League group ... at this moment in time, it is better now than at the World Cup," Flick said.
"It is also a personal motivation for everyone to give it all (against England) on Monday and put in the work in the next six weeks to add these few percentage points that we need to add. The defeat opened our eyes.
"The first half was very bad. We were not active and without any confidence. The second half was good but we had far too few chances to score."
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.