Sweden substitute Viktor Claesson scored a 93rd-minute winner as a valiant Poland fightback proved in vain and they were eliminated from Euro 2020.
In a captivating game in St Petersburg, Sweden led 2-0 at the hour mark thanks to two goals from Emil Forsberg.
But a Robert Lewandowski double put Poland within a goal of the win they needed to advance – only for Claesson to end their hopes.
Sweden will now prepare for a last-16 tie against Finland or Ukraine at Glasgow’s Hampden Park on 29 June.
Spain earned their first win at Euro 2020 in style as they thrashed Slovakia to progress as Group E runners-up and set up a last-16 tie with Croatia.
Luis Enrique’s side head into the knockout stages on the back of their best attacking display of the tournament, proving far too good for a seriously below-par Slovakia.
Aymeric Laporte, Pablo Sarabia and Ferran Torres all scored after a bizarre own goal from Newcastle’s Martin Dubravka broke the deadlock at La Cartuja Stadium in Seville.
The Slovakia goalkeeper, who earlier saved a penalty from Alvaro Morata, punched the ball into his own net after Sarabia’s effort hit the crossbar and looped into the air.
Juraj Kucka inadvertently completed the rout for Spain, bundling the ball over his own line from close range.
Spain’s meeting with Croatia will take place in Copenhagen on Monday, while Slovakia are out.