Niclas Fullkrug proved the last-gasp hero as Germany avoided a shock upset to top Group A at Euro 2024 after snatching a 1-1 draw with Switzerland on Sunday.
Dan Ndoye's first international goal seemed set to seal a famous win for Switzerland and ensure them top spot in Group A, but Germany's towering substitute stepped up in the dying seconds in Frankfurt.
Ruben Vargas thought he had doubled Switzerland's advantage late on, only to be denied by the offside flag, and that decision proved pivotal when Fullkrug headed in his 92nd-minute leveller.
That late intervention ensured Germany finished top of the group and will face second place in Group D in the last 16, while Switzerland's top-two finish sets up a meeting with the runners-up of Group B.
The host nation started brightly once again and thought they had taken another early lead when Florian Wirtz teed up Robert Andrich, who squeezed his shot past Yann Sommer into the near post.
However, the Bayer Leverkusen midfielder was denied his first international goal after a VAR check as Jamal Musiala was deemed to have fouled Michel Aebischer in the box during the build-up.
Nagelsmann's team instead found themselves behind for the first time in the tournament just before the half-hour mark after Ndoye crashed Remo Freuler's whipped cross past the helpless Manuel Neuer.
Just moments later, Ndoye offered Germany another scare, racing past Antonio Rudiger before fizzing an angled shot just wide of the far post.
Nagelsmann's half-time message was clear as Musiala looked to make it three goals in three games with a powerful hit from the edge of the box, but Sommer was equal to the attempt.
Toni Kroos drilled a low shot wide under pressure before Kai Havertz glanced a header over the bar as Germany failed to find their clinical edge.
Joshua Kimmich had the best chance to equalise from close range in the 71st minute, but an incredible last-ditch block by Manuel Akanji denied him.
Vargas was left one-on-one with Neuer shortly after and slotted into the far corner, but the assistant referee was quick to flag for offside as Switzerland celebrations were short-lived.
Havertz's looping header bounced off the crossbar as Germany sought a response, which arrived when Fullkrug made his impact off the bench, thumping a header home from David Raum's left-sided delivery.
Neuer's record-breaking day salvaged by Fullkrug
Neuer had already made history in their opening game at Euro 2024 as he became Germany's outright top appearance maker at major tournaments, surpassing Philipp Lahm.
Now, on his 37th start for his country, only Cristiano Ronaldo (45) has played more games across the Euros and World Cup than him, while he has also made the most appearances among goalkeepers in the history of the competition (18, moving ahead of Gianluigi Buffon).
The 38-year-old could not mark a special day with a win, though, as Germany's long wait for a comeback victory when trailing at half-time stretched to 11 matches in the competition (D2 L9).
Their last such win came at Euro 1976 against Yugoslavia (2-0 down at half-time, won 4-2), but Neuer and Co. can at least celebrate top spot after late drama in Frankfurt.
Ndoye steps into the spotlight
Xherdan Shaqiri grabbed the headlines in Switzerland's 1-1 draw with Scotland last time out after scoring in a sixth consecutive major tournament, but with him on the bench on Sunday, the Red Crosses needed others to step up.
In his 14th start for the national side, Ndoye netted for the first time, becoming Switzerland's second-youngest goalscorer in the history of the Euros at 23 years and 242 days, after Johan Vonlanthen against France in 2004 (18y 141d).
Despite going off in the 65th minute, Ndoye had the most shots for Switzerland (two of their three), creating an expected goals tally of 0.52 as he proved their biggest threat.
Though Switzerland will rue their late concession, they are now unbeaten in their last four meetings with Germany – a promising sign as the last-16 awaits.