Niclas Fullkrug scored in stoppage time to earn Germany a 1-1 draw with Switzerland and secure top spot in Group A.
The Swiss looked set to claim a famous victory after Dan Ndoye netted in the 28th minute, with Germany unable to create many clear-cut opportunities.
But, two minutes into time added on, David Raum sent in a fine cross from the left and fellow substitute Fullkrug met it with a perfect header into the corner of the net.
The result means Germany finish top with seven points, while Switzerland are also guaranteed to reach the last 16 in second place.
Germany stuck with the same team despite having already secured their progress, while Breel Embolo and Fabian Rieder came in for Xherdan Shaqiri and Ruben Vargas for Switzerland.
There was an early warning for the Swiss of the threat of Jamal Musiala, who ran down the right before playing in Ilkay Gundogan, with Fabian Schar getting in quickly to clear.
From the corner, Florian Wirtz had a free header, but he could only direct it straight at goalkeeper Yann Sommer.
The Swiss goalkeeper’s blushes were then spared in the 17th minute after he was beaten at his near post from 25 yards by Robert Andrich, who thought he had scored his first goal for Germany.
But a VAR review saw the effort chalked off, with Musiala adjudged to have fouled Michael Aebischer as he cleared a cross from Maximilian Mittelstadt in the build-up.
And 11 minutes later it was Switzerland’s fans celebrating after Bologna’s Ndoye met a cross from Remo Freuler with a fine volleyed finish. There was another VAR check, for offside, but this time the goal stood.
Ndoye almost scored a second immediately, this time shooting across goal and just wide of Manuel Neuer’s far post from the corner of the box.
Germany were then dealt another blow when Jonathan Tah was shown a yellow card for a very high challenge, ruling him out of their last-16 clash.
The hosts were struggling to break down the organised and energetic Swiss. They had a couple of openings at the start of the second half but Musiala fired a sharp shot straight at Sommer and Toni Kroos sent an effort from the edge of the box well wide.
Kai Havertz then headed over before Joshua Kimmich was denied by a brilliant block from Manuel Akanji when an equaliser looked to be forthcoming.
Vargas thought he had doubled Switzerland’s lead and secured the points when he slotted beyond Neuer with six minutes left but he was denied by an offside flag.
Neuer then kept Germany in it with a fine save to keep out a curling effort from Granit Xhaka, and shortly afterwards they found the moment they had been looking for.