Germany survived a scare to finish top of Group A at Euro 2024 as Niclas Fuellkrug's stoppage-time goal rescued a 1-1 draw against Switzerland, while Scotland were eliminated after a last-gasp 1-0 defeat against Hungary whose striker Barnabas Varga suffered a sickening injury.
Dan Ndoye's first-half goal in Frankfurt had put Switzerland on course to climb above hosts Germany into top spot.
But Fuellkrug's late header ensured Julian Nagelsmann's side advanced to the last 16 in pole position with seven points.
The Germans, who last won the Euros in 1996, will take on the Group C runners-up -- currently slated to be Denmark -- in the last 16.
Denmark, two points behind leaders England, play Serbia in their last group game on Tuesday.
Germany are also on track for a potential quarter-final clash with Spain, who have been among the best teams at the tournament so far.
Switzerland, who reached the quarter-finals at the last Euros in 2021, have now made the knockout stage in six successive major tournaments.
As Group A runners-up with five points, the Swiss will face the second-placed team in Group B in the last 16.
Although Germany were already through to the last 16 after beating Scotland and Hungary, Nagelsmann opted against resting his stars as he named an unchanged team for a third successive game.
Switzerland took a shock lead in the 28th minute as Ndoye met Remo Freuler's cross with a close-range volley that flashed past Germany goalkeeper Manuel Neuer.
Ndoye's first international goal was made in Bologna as both he and Freuler played for the Serie A club last season.
Adding to Germany's problems, Jonathan Tah was booked, earning the centre-back a ban for the first knockout game.
Germany dominated possession but Ilkay Gundogan scuffed wide with the goal at his mercy after Yann Sommer parried Jamal Musiala's stinging strike into the midfielder's path.
Their pressure was finally rewarded in stoppage-time when Fuellkrug rose highest to power his header into the top corner.
In Stuttgart, Scotland were unable to secure the victory that would likely have taken them into the knockout stage of a major tournament for the first time.
In 11 previous appearances at major competitions -- eight World Cups and three European Championships -- Scotland had bowed out at the group stage.
Once again, they will fly home early after taking just one point from their three matches.
Steve Clarke's team, who lost to Germany and drew with Switzerland in their first two games, were sunk by a goal 10 minutes into stoppage-time from Kevin Csoboth, whose clinical finish capped a rapid raid from the Hungarians.
Hungary may not secure a last 16 berth despite their victory as they have only three points from their three games.
The four third-placed teams with the best records from the six groups will move into the last 16.
Hungary's win came at a cost as Varga was stretchered off after a sickening collision.
Varga collapsed to the pitch and was struggling to move after chasing a long cross into the area as Scotland goalkeeper Angus Gunn came to collect the ball.
After a long delay, medics took the 29-year-old from the pitch while a sheet was draped around the stretcher.
Hungary captain Dominik Szoboszlai appeared to be in tears as he consoled his stricken teammate.
Varga was immediately taken to hospital after the incident where he was said to be conscious and talking.
"The condition of Barnabas Varga is stable," the Hungarian Football Federation (MLSZ) wrote on X.
"The Hungarian national team player is currently in one of the hospitals in Stuttgart. We will inform you immediately if there is any news on his status."
In Group B on Monday, Italy take on Croatia, while Spain, already qualified in first place, face Albania.
Italy are second in the group with three points, while Croatia and Albania both have one point.