Sweden secured top spot in Group E with a last-gasp 3-2 win as Poland were eliminated despite two goals from Robert Lewandowski.
Only a win could have kept Poland in Euro 2020 but any hope of that appeared to have gone when Emil Forsberg followed up his goal in the second minute with another after the break.
But Lewandowski, who had struck the crossbar twice in the first half, pulled one back with a wonderful shot on the angle before conjuring up an unlikely equaliser late on.
As Paulo Sousa's side pushed hard for the winning goal they needed they left spaces at the back and substitute Viktor Claesson capitalised to win the game in stoppage time.
That goal moved Janne Andersson's Sweden above Spain in Group E and they now travel to Glasgow to face Ukraine or the Czech Republic depending on what happens later in the evening in Group F.
Sweden: Olsen (7), Lustig (7), Lindelof (6), Danielson (5), Augustinsson (6), Larsson (6), Olsson (6), Ekdal (6), Forsberg (8), Quaison (7), Isak (6)
Subs: Kulusevski (7), Berg (6), Krafth (6), Claesson (7)
Poland: Szczesny (6), Bereszynski (6), Glik (6), Bednarek (6), Jozwiak (4), Krychowiak (6), Klich (6), Puchacz (5), Swiderski (6), Zielinski (6), Lewandowski (8)
Subs: Frankowski (8), Swierczok (6), Kozlowski (6), Placheta (6)
Man of the match: Emil Forsberg
- How the teams lined up | In-depth stats and analysis
- Subscribe to Sky Sports' Euro 2020 podcast
- Euro 2020 fixtures and schedule | Euro 2020 gossip column
How Sweden eliminated Poland
For all the permutations at this stage of the competition, there was clarity for Poland coming into the game - win or go home - but the task became tougher inside two minutes.
Forsberg capitalised on hapless defending by Kamil Jozwiak inside the area before lashing the ball left-footed beyond the outstretched left hand of goalkeeper Wojciech Szczesny.
The ball hit the net after 81 seconds, making it the second fastest goal in European Championships history, and there was no immediate response from Poland.
Sweden made one change to the team that edged past Slovakia. Marcus Berg dropped to the bench to be replaced by Robin Quaison, the man who won the penalty in that game.
Poland made one change to the team that drew with Spain. The injured Jakub Moder made way with Grzegorz Krychowiak returning from suspension following his red card against Slovakia.
Alexander Isak had the chance to double the lead soon after, rolling Kamil Glik with ease but failing to find strike partner Robin Quaison who was unmarked in the middle of the box.
Poland's first chance to equalise came in the 17th minute and it was a huge opportunity as Lewandowski hit the crossbar twice in quick succession with Robin Olsen beaten.
The header from the corner was an impressive one but the Bayern Munich forward should have done much better with the follow-up attempt as the goal was gaping.
Despite plenty of possession that was as close as Poland came in the first half as their delivery from wide areas was particularly poor. Sweden were relatively untroubled.
That changed in the second half as Poland's urgency became apparent with Olsen forced into a good save low to his right from Grzegorz Krychowiak's probing long-range effort.
But the introduction of Juventus winger Dejan Kulusevski was the catalyst for Sweden's second as his mazy run teed up Forsberg to stroke the ball beyond Szczesny again.
That left Poland in dire trouble, although it did seem to inspire them. Within minutes, Lewandowski found rare space in the left channel and curled the ball into the far corner of the net.
A narrow offside decision midway through the second half denied Jakub Swierczok an equaliser as Poland threw everything at Sweden, the tempo of their game raised.
Finally, the breakthrough came. Impressive substitute Przemyslaw Frankowski swung in the cross and poor defending allowed Lewandowski time to slot home with his left foot.
It sparked a frenzied finish as Poland tossed the ball into the Sweden box but with time running out they were punished on the counter-attack by Claesson's neat finish.
Man of the Match - Emil Forsberg
There were plenty of candidates. Robert Lewandowski almost turned the game back in Poland's favour with two goals, helped by the impact of Przemyslaw Frankowski off the bench. Sweden's substitutes were just as impressive, Dejan Kulusevski providing two assists and Viktor Claesson scoring the winner.
But before all that, it was the performance of Forsberg that shaped the game. The midfielder scored the first two goals and both were brilliantly struck finishes - the first coming with his left foot and the second with his right. Each was hit with force. Each was placed beyond the goalkeeper.
The absence of Zlatan Ibrahimovic has robbed Janne Andersson of his most likely source of goals and that meant someone had to step up. Forsberg did so here and with him in this form, it might force a reassessment of the potency of an otherwise workmanlike side.
● Scored after just 81 seconds, Emil Forsberg's opener for Sweden against Poland was the second-fastest goal ever scored from the start of a European Championship match, after Dmitry Kirichenko for Russia v Greece in 2004 (65 seconds).
● Sweden's Emil Forsberg has scored in consecutive major tournament apps (Euros/World Cups), after scoring in just one of his previous nine. Forsberg has netted three goals from three shots on target at EURO 2020.
● Sweden's Dejan Kulusevski (21y 59d) became the youngest player to assist two goals in a single game at the European Championships since Cesc Fàbregas (21y 53d) v Russia in 2008.
● Robert Lewandowski has scored in consecutive major tournament appearances for the first time in his career (Euros/World Cups). In fact, he is now Poland's highest scoring player in European Championship history (5).