A superb first-half strike from Adam Szalai gave Hungary a 1-0 win over Germany at Leipzig's Red Bull Arena on Friday.
The win cemented Hungary's position on top of the group standings, with the unbeaten side only needing a draw in their final match away against Italy to secure top spot.
Playing his second-last game before retiring from international football, striker Szalai gave Hungary the lead after 17 minutes.
Szalai, who is at Swiss side Basel after a career which took him to five different Bundesliga sides, won Hungary a corner off Real Madrid centre-back Antonio Rudiger.
Leipzig midfielder sent the corner goalwards, before Szalai skilfully clipped the ball into the net with his heel.
Germany had just one chance in the first half when Bayern forward Thomas Muller leapt high to meet Leipzig wing-back David Raum's cross, but the ball was headed directly at Hungary keeper Peter Gulacsi.
Coach Hansi Flick replaced Bayern's Serge Gnabry at half-time with West Ham right back Thilo Kehrer, with the forward's stuttering club form carrying through to the international stage.
The change freed up Gladbach's Jonas Hoffmann, who started at right back, into his familiar attacking midfielder position.
The change almost paid immediate dividends, with Hoffmann setting up Muller to score an apparent equaliser, but the goal was correctly ruled out for a narrow offside against the Gladbach captain.
Germany continued to grow into the game, with Bayern forward Joshua Kimmich, Germany's best player on the night, inches away from a long-range equaliser in the 60th minute.
Despite the home side's dominance in possession, Hungary remained dangerous on the counter, with only the fingertips of Germany goalkeeper Marc-Andre ter Stegen stopping Martin Adam from doubling the visitors' lead after 72 minutes.
In the dying stages, Kimmich went close again with a skimming shot from the edge of the box on the 86th-minute mark, but the ball bounced wide of the left-hand post.
The loss was Germany's first under former Bayern manager Flick, who had won nine and drawn four of his previous 13 games in charge.