Germany will face England in the last 16 of Euro 2020 after twice coming from behind to knock battling Hungary out of the tournament.
Germany finished second in Group F after a 2-2 draw with Hungry.
France topped the group after a 2-2 draw with Portugal, who finished third.
In an extraordinary match, Germany were minutes away from making an embarrassing early exit when midfielder Leon Goretzka, on as a substitute, equalised in the 84th minute.
Cristiano Ronaldo equalled the men's all-time international goalscoring record as defending champions Portugal drew with France to qualify for the last 16 as one of the best third-placed teams.
France now meet Switzerland while Portugal play Belgium.
Spain have recorded the biggest win of Euro 2020 to set up a last 16 match with Croatia.
The 2008 and 2012 champions crushed a hapless Slovakia 5-0 in Seville being set on their way by a calamitous own-goal from keeper Martin Dubravka.
Sweden winger Emil Forsberg scored a double including the second fastest strike in European Championship history before Viktor Claesson's stoppage-time goal helped them seal a 3-2 win over Poland and top spot in Group E.
Last 16 draw:
Wales vs Denmark
Italy vs Austria
Netherlands vs Czech Republic
Belgium vs Portugal
Croatia vs Spain
France vs Switzerland.
-BBC/Reuters