Alvaro Morata and Mikel Oyarzabal scored extra-time goals to earn Spain a 5-3 win over Croatia in Monday's breathless Euro 2020 last-16 tie after La Roja had squandered a two-goal lead late on in normal time.
Spain recovered from a bizarre Pedri own goal at Parken Stadium thanks to strikes from Pablo Sarabia, Cesar Azpilicueta and Ferran Torres to lead 3-1 with 85 minutes played.
However, Mislav Orsic bundled in to give Croatia a lifeline in Copenhagen and then set up fellow substitute Mario Pasalic in the 92nd minute to take an enthralling game to extra time.
But Spain dug deep in the additional period to book a place in the quarter-finals, where either France or Switzerland await, with Morata making amends for an earlier miss with a well-taken goal and Oyarzabal adding a second from the bench to settle a game that will go down as a European Championship classic.
Profligacy cost Spain in their opening two group games and that looked like being the case again in Copenhagen after Koke was denied by Dominik Livakovic from a one-on-one and Morata headed into Domagoj Vida from close range.
A comical moment followed as Pedri's pass from 49.4 yards was miscontrolled by Unai Simon and rolled into the back of the net, making it the longest-range own goal in European Championship history.
Luis Enrique's men responded well by equalising before half-time through Sarabia's powerful drive after Jose Gaya's shot was parried into his path by Livakovic.
Azpilicueta put Spain in front with his first international goal by getting in front of Josko Gvardiol and guiding Torres' cross past Livakovic from inside the six-yard box.
Spain gave themselves breathing space nine minutes later as Torres cut inside and clinically finished off a swift move.
With five minutes to go, though, Orsic followed up after a scramble in the box to help the ball over the line – the goal allowed to stand following a VAR check for handball inside the box.
Then came the dramatic leveller in added time, with Pasalic left in space inside the box to head in Orsic's cross and pave the way for an additional 30 minutes.
Croatia started the period of extra time on top and would have taken the lead if not for an incredible Simon stop to keep out Andrej Kramaric, but Morata took down Dani Olmo's cross at the back post and thumped past Livakovic four minutes later.
Super sub Olmo then provided the cross for fellow replacement Oyarzabal, who also hit the post in the final seconds, to tuck home the eighth goal of a sensational European Championship tie and confirm Spain's place in the last eight.
What does it mean? Spain edge crazy clash in Copenhagen
From the moment Pedri scored the first ever European Championship own goal from outside the box, it was clear this match was going to be one to remember.
So it proved, with Spain recovering brilliantly only to then somehow throw away a commanding lead late on in the match, in doing so conceding three goals for just the second time in their Euros history.
But Spain showed good resolve in extra time and got themselves over the line, with five different goalscorers registering for La Roja in a single major tournament match for the first time ever.
La Roja run riot
Spain were heavily criticised after wasting a string of chances in their first two group matches, but they have since put five goals past Slovakia and Croatia, making them the first side in Euros history to score five or more times in successive games.
Oyarzabal and Olmo made a huge difference for La Roja, but credit must also go to Morata – the target of abuse after those first two matches – as his fifth Euros goal, which takes him level with Fernando Torres, helped rescue his side.
Pedri continues own goal trend
Pedri's own goal was the ninth scored at Euro 2020, matching the tally from the previous 15 editions combined.
The Barcelona midfielder was otherwise superb, though, on the day he became the youngest ever player to start a knockout game in the European Championships at 18 years and 215 days, overtaking the record of Wayne Rooney in 2004.
Key Opta facts:
– Courtesy of the eight goals in the game, Croatia and Spain produced the second-highest-scoring match in European Championship history, after France v Yugoslavia in the 1960 semi-finals (5-4 to Yugoslavia).
– Croatia have netted seven goals at Euro 2020, their highest tally at an edition of the European Championships.
– Pedri's own goal was Spain's first ever in the European Championships and came at a distance of 49 yards, the longest-ever own goal netted in the competition and the first one ever scored from outside the box.
– Azpilicueta scored his first ever goal for Spain on his 27th cap, becoming La Roja's oldest ever goalscorer at the European Championships (31y 304d).
– Orsic became the first substitute to both score and assist for Croatia in a single major tournament match (World Cup and Euros).
Spain now have four days to prepare for a quarter-final showdown against either France or Switzerland in Saint Petersburg. As for Croatia, they are not back in action until early September with a World Cup qualifier against Russia.