Spain profited from Martin Dubravka's goalkeeping howler and then turned on the style to thrash Slovakia 5-0 and book their place in the last 16 of Euro 2020.
Luis Enrique's men required a win in Thursday's (AEST) clash to guarantee progression after drawing their first two games and they were given a huge helping hand by Dubravka.
The Slovakia keeper saved an Alvaro Morata penalty early on – the fifth in a row Spain have missed – before comically flapping the ball into his own net with half an hour played.
That put Spain on their way to an emphatic win, the first time they have ever scored five times in a European Championship match.
Aymeric Laporte's first international goal made it two before the break and strikes from Pablo Sarabia and Ferran Torres, plus Juraj Kucka's own goal, made certain of victory after the interval.
Spain were awarded a penalty inside the first 12 minutes after the VAR intervened and adjudged Jakub Hromada to have fouled Koke when attempting to clear the ball.
Dubravka dived to his right and got two hands to the powerful attempt but, after chances went begging for Sarabia and Pedri, the keeper went from hero to zero.
Sarabia's long-range shot looped into the air after striking the crossbar and Dubravka, under a bit of pressure from Morata, inexplicably pushed the ball into his own net.
Dubravka could have done better for Spain's second goal, too, as Gerard Moreno beat the marauding keeper to a ball and crossed for Laporte to head into the top-right corner.
Spain were in complete control of the game when Sarabia swept home Jordi Alba's pass into the bottom-right corner with 56 minutes on the clock.
Slovakia still had a chance of advancing as one of the best third-placed sides, but substitute Torres flicked Sarabia's cross past Dubravka just 44 seconds after entering the pitch and Kucka knocked the ball into his own net soon after for Spain's fifth.
What does it mean? Spain get lift-off – but miss out on top spot
Group E was wide open heading into the final round of matches and it served up a dramatic conclusion, with Sweden grabbing top spot courtesy of a last-gasp 3-2 win against Poland in a game that saw them squander a two-goal lead.
Despite this impressive win for Spain, which was the joint-largest margin of victory by any side in a European Championship match, they must settle for second place and a last-16 tie with World Cup 2018 runners-up Croatia in Copenhagen next Tuesday.
Dubravka's helping hand
Only Dubravka himself will know exactly what he was attempting when helping the loose ball over the line for one of the European Championship's most iconic own goals.
In doing so, he is the first keeper to save a penalty and score an own goal in the same Euros game. It is also the first time Spain have benefited from an OG in the competition, and they used that moment of fortune as a springboard to pick up a record-equalling victory.
Morata's drought goes on
Morata has endured a pretty torrid tournament so far. He played a big part in a couple of Spain's goals against Slovakia, but this performance will be remembered for his penalty miss.
He has had six shots on target so far at Euro 2020 without finding the net, including three in this win, which is the most of any player in the competition.
Spain have five days to prepare for their last-16 clash with Croatia. Slovakia's tournament is over, and they now have a little over two months before returning to action with a World Cup qualifier against Slovenia.