Denmark stormed to a brilliant and emotional 4-1 win over Russia in Copenhagen to claim second spot in Group B and set up a last-16 tie against Wales, as Belgium's win over Finland helped them into the automatic spots.
At the same venue where, just over a week ago, Denmark and their supporters were left shocked and upset by Christian Eriksen's cardiac arrest, there were wild celebrations as the Danes produced a superb performance to blow away their visitors.
Twenty-year-old Mikkel Damsgaard (38) got the ball rolling with a wonderful, dipping strike from the edge of the box and Yussuf Poulsen (59) profited from an awful back-pass to double that lead.
At that point Denmark were only looking to bolster their chances of going through as one of the best third-placed sides and they suffered a setback when Artem Dzyuba (70) pulled one back with a penalty and Belgium had a goal ruled out against Finland in the space of a minute.
But circumstances swung Denmark's way from then on, with Andreas Christensen (79) and Joakim Maehle (82) lashing in from the edge of the box as the much-changed group winners Belgium eventually saw off Finland.
Denmark's players huddled together in the centre circle to watch the final moments of that match and then jumped for joy when the result confirmed their runners-up spot, leaving Finland third and Russia bottom of the pile.
Denmark will now play Wales on Saturday at 5pm in Amsterdam.
Russia: Safonov (6), Dzhikiya (5), Kudryashov (5), Diveev (6), Kuzyaev (3), Golovin (6), Zobnin (5), Ozdoev (5), Fernandes (6), Dzyuba (7), Miranchuk (5).
Subs: Karavaev (5), Sobolev (7), Zhemaletdinov (5), Mukhin (5).
Denmark: Schmeichel (7), Kjaer (7), Christensen (8), Vestergaard (5), Hojbjerg (7), Wass (6), Delaney (6), Maehle (8), Poulsen (8), Braithwaite (7), Damsgaard (8).
Subs: Larsen (6), Dolberg (6), Norgaard (6), Jensen (N/A), Cornelius (N/A)
Man of the Match: Joakim Maehle (Denmark)
How Denmark did it...
Denmark, who began the night in fourth, knew they had it all to do to make the last 16 and came out of the traps quickly, sending a series of crosses into the Russia box, but it was the visitors who created the first real chance, with Aleksandr Golovin firing at Kasper Schmeichel after a fine driving run from midfield.
Aleksey Miranchuk sparked another break forwards when he won back possession in the centre circle but Roman Zobnin couldn't find the pass to the free men Russia had racing clear on the left flank.
Russia made one change, with Fedor Kudryashov replacing Dmitri Barinov, and Mario Fernandes fit to start.
Denmark were unchanged.
Denmark continued to be held at arm's length by Russia, with Pierre-Emile Hojbjerg trying his luck with a blast from 35 yards, before Golovin sent a shot way over the bar from a Dzyuba knock-down on 35 minutes.
Three minutes later, Damsgaard showed the pair of them how to do it from distance.
The highly-rated youngster received a pass from Hojbjerg on the half-turn around 25 yards out, shifted it a yard to his right and looped a wonderful effort into the top corner to send the 25,000 home fans wild.
- How the teams lined up | In-depth stats and analysis
- Euro 2020 group tables | Who needs what to qualify for last 16?
Despite enjoying 68 per cent possession in the first half, that was Denmark's first shot on target but there was more cutting edge in the final third after the break.
Martin Braithwaite had mis-controlled at the vital moment after a cut-back from Daniel Wass soon after the restart but there was no way Poulsen was going to miss when Daler Kuzyaev played a blind back pass right into his path.
But Denmark's bouncing supporters had to check themselves soon after, as celebrations of a Romelu Lukaku goal against Finland were cut short by VAR and, almost simultaneously, Russia won a penalty when sub Alexander Sobolev was pulled down in the box by Jannick Vestergaard.
With Dzyuba scoring down the middle, progression from their position of third looked unlikely for Denmark. They needed more goals - and a favour from Roberto Martinez's side in St Petersburg. They got both.
First Thomas Vermaelen's header bounced off the woodwork and in off Finland goalkeeper Lukas Hradecky to lift Denmark up to second. Then came a quickfire double from the Danes to put them out of sight against Russia.
Christensen rifled home in spectacular fashion from 25 yards after a loose ball came his way, and then standout performer Maehle got reward for his evening's work, drilling in a fourth. Both players signalled the number 10 in honour of Eriksen after scoring.
The party in the Parken Stadium took off and only got louder when Lukaku put Belgium two up and Denmark knew they were definitely going through.
After the trauma of their opening game, their recovery to qualify is one of the feel-good stories of the tournament. And it's not over yet...
Opta stats - A Euros record for Denmark
- Denmark are the first team in European Championship history to reach the knockout stages of the competition having lost their first two group stage games.
- Russia conceded 4+ goals in a major tournament game for only the second time, after losing 4-1 to Spain in the Euro 2008 Group Stages (excluding games as USSR).
- Russian players have made three errors leading to goals at Euro 2020, more than any other side and the joint-most by any side in the competition (since 1980).
- Mikkel Damsgaard has been directly involved in six goals in his five appearances for Denmark in all competitions, scoring three and assisting three.
- At 20 years and 353 days, Damsgaard has become Denmark's youngest ever goalscorer at a major international tournament, with the striker also the first player born in the 2000s to score in the European Championships.
Denmark will now play Wales in the last-16 tie in Amsterdam on Saturday at 5pm.