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 Ukraine at Glasgow’s Hampden Park on 29 June.
The Swedes netted their first goal from open play at the tournament just 82 seconds into their final Group E game thanks to Forsberg’s composed angled finish.
The RB Leipzig midfielder doubled the lead with a first-time shot – his third goal at the tournament – before Lewandowski produced a quality arrowed finish.
The Bayern Munich striker then conjured an 84th-minute equaliser, but Claesson’s late goal was decisive.
Poland captain Lewandowski was earlier guilty of an incredible miss with Sweden leading 1-0.
After heading against the underside of the bar from a corner, his follow-up header from just two yards out struck the bar.
Another disappointing exit for Poland
When Poland replaced manager Jerzy Brzeczek with Portuguese Paulo Sousa in January, the reasoning from the Polish FA was that they wanted to see a more attacking style to get the best out of forward Lewandowski.
The 32-year-old, who scored 41 times in the Bundesliga in 2020-21, departs the tournament having netted three goals. It would have been four but for his incredible 17th-minute miss.
After his initial downward header bounced up and hit the underside of the bar, it rebounded back into Lewandowski’s path only for him to hit the woodwork again when it looked easier to score.
Piotr Zielinski had two long-range efforts saved by Robin Olsen, who also kept out Grzegorz Krychowiak.
Poland poured forward in the second half but Sweden, with Marcus Danielson and Victor Lindelof at the centre of defence, advance to the knockout stage with confidence sky high after two wins and a draw from three group games.