Viktor Claesson (L) celebrates his late winner against Poland
Viktor Claesson scored an injury-time winner as Sweden beat Poland 3-2 in Saint Petersburg on Wednesday to clinch top spot in Group E and knock their opponents out of Euro 2020.
Emil Forsberg struck twice, the first coming after just 81 seconds, but Robert Lewandowski's double gave Poland hope of qualifying before Claesson's late goal sent Sweden through as group winners.
Sweden will likely play Ukraine in the last 16 after pipping Spain to first place, with Slovakia exiting alongside Poland following a crushing 5-0 defeat in Seville.
"It's a great to win the group like at the 2018 World Cup. We'll have a bit more time to rest than if we'd finished second or third," said Sweden coach Janne Andersson.
"We should have kept the 2-0 lead for longer but Lewandowski scored a fantastic goal. It was a great feeling at the end. The players are warriors and their sense of sacrifice deserves praise."
After losing to eventual winners Portugal on penalties in the quarter-finals of Euro 2016, Poland have now gone out in the group stage at the past two major finals.
"We are disappointed, myself, my staff and all my players because we deserved much more than what we got," said Poland coach Paulo Sousa.
"We need to be much stronger in the near future. We cannot concede silly goals like we have been."
Sweden, safe in the knowledge they were assured of a place in the next round before kick-off, made a dream start as Forsberg scored for the second game in a row, netting the second-fastest goal in European Championship history.
The RB Leipzig attacker collected a loose ball just outside the Poland area after Kamil Glik flattened Alexander Isak, riding a challenge from Kamil Jozwiak before firing into the far corner.
With Poland needing victory to avoid elimination Lewandowski hit the crossbar twice in a matter of seconds, incredibly failing to convert his own rebound from point-blank range after connecting with Piotr Zielinski's corner.
Zielinski forced Robin Olsen into a pair of flying saves with shots from distance either side of half-time, with the Sweden goalkeeper also making a fine stop from Grzegorz Krychowiak's long-range shot.
Juventus winger Dejan Kulusevski came on 10 minutes into the second half for his first appearance after testing positive for Covid-19 just before the tournament.
His driving run and pass set up Forsberg to curl in Sweden's second on 59 minutes, but Poland responded to set up a thrilling finish.
Lewandowski halved the deficit with a brilliant solo effort on 61 minutes, bending into the top corner to become his country's all-time leading scorer at the tournament.
Poland had not scored more than once in any of their previous 13 matches at the finals, but Lewandowski took advantage of confusion between Victor Lindelof and Marcus Danielson to equalise six minutes from time.
As Poland desperately pushed for a winner, Sweden snatched all three points right at the death when Kulusevski played in fellow substitute Claesson to slot beyond Wojciech Szczesny.