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.
Â
Â