Despair turned to exhilaration for Denmark as they claimed an astonishing 4-1 victory over Russia to scramble into the last 16 of Euro 2020 on a wonderful night in Copenhagen.
Needing a victory to have any chance of progression, Mikkel Damsgaard lit the touchpaper with a 38th-minute wonder goal on a head-spinning night in the Parken Stadium.
A dreadful mistake by Russia's Roman Zobnin allowed Yussuf Poulsen to double the lead on the hour.
Russia threatened a comeback when Artem Dzyuba converted a 70th-minute penalty but Andreas Christensen's screamer made it 3-1 before Joakim Maehle completed the rout.
It was only half the story though as Denmark's fate was never in their own hands and they were still indebted to Belgium who beat Finland 2-0 in St Petersburg.
Having lost their opening two games in the wake of Christian Eriksen's cardiac arrest in the opener against Finland, Denmark went through as runners-up and will face Wales next.
Belgium finished top of Group B with a maximum nine points with Denmark, Finland and Russia all on three points, but with the Danes ahead on goal difference.
Other than a Pierre-Emile Hojbjerg shot that fizzed wide early on, Denmark were struggling to make much headway against a disciplined Russian side for whom Alexander Golovin could have opened the scoring after a weaving run.
With no margin for error in their quest to stay in the tournament, there was tension about Denmark's play and Russia had turned down the volume of the fervent home support.
But that all changed with a moment of magic from Damsgaard, Eriksen's replacement, in the 38th minute.
Receiving a pass from Hojbjerg, he took a silky touch with his left foot and opened his body to swerve a majestic shot beyond Russia keeper Matvei Safonov.
If Denmark's opener was sublime, then their second on the hour mark was ridiculous. Zobnin inexplicably played a pass back towards his keeper without looking and Poulsen completed the simplest of tasks to score.
Denmark were rampant but in the space of seconds everything went flat as Russia were awarded a penalty after Jannik Vestergaard fouled Alexander Sobolev - and giant striker Dzyuba thumped the ball past Kasper Schmeichel to revive Russian hopes.
As news drifted through that Belgium had taken the lead against Finland, the mood turned to jubilation as Christensen and Maehle completed a sensational evening.
Relentless Belgium win again to leave Finn hopes hanging
Belgium continued their perfect start to Euro 2020 by beating Finland 2-0, to finish top of Group B, leaving the Finns third and facing a nervous wait to see if they can sneak into the knockout stages.
A much-changed Belgium side dominated the game but only found a breakthrough in the 74th minute courtesy of an own goal from keeper Lukas Hradecky, who fumbled a Thomas Vermaelen header over the line after it had crashed off the woodwork.
Striker Romelu Lukaku clinched victory in the 83rd minute by swivelling to thump home a Kevin de Bruyne pass and score his third goal of the tournament.
Belgium, who became the third team after Italy and the Netherlands to win all three group games, will face one of the third-placed sides in Seville on June 28.
Finland must wait to see if they qualify to continue the adventure in their first-ever major tournament.
Belgium coach Roberto Martinez made changes from the side that beat Denmark 2-1 but it was still a line-up bursting with world-class talent as Eden Hazard and Kevin de Bruyne made their first starts of the tournament.
Teenager Jeremy Doku was their liveliest threat and created the only real moment of danger before halftime when he drifted in from the left-wing and aimed a shot towards the bottom corner but Hradecky made a fine save.
Finland defended resolutely but did not have a real chance of their own until after the hour mark when Glen Kamara fired straight at Thibaut Courtois.
Hazard was denied by a big save from Hradecky as Belgium kept getting closer and they thought they had taken the lead when Lukaku controlled a threaded pass from De Bruyne and celebrated the goal before a lengthy VAR review ruled him fractionally offside.
Finland finally cracked under the pressure when Hradecky turned the ball over the line after Vermaelen's thumping header struck the post.
Lukaku then used a combination of skill and power to seal the victory and continue his prolific start to the tournament.