Luis Enrique’s side were rocked when Croatia substitutes Mislav Orsic and Mario Pasalic scored twice in the final five minutes to come back from 3-1 down and force extra time, but Spain rallied as the added 30 minutes produced yet more drama.
Striker Alvaro Morata, who revealed before the match that his family have been threatened during the tournament as a result of his performances, silenced his critics when he thumped in Spain’s fourth goal in extra time in Copenhagen.
The scoring did not end there as Mikel Oyarzabal added a fifth goal three minutes later to finally see off Croatia, who had fought bravely in this highly entertaining last-16 tie.
In a hint of what was to come, 20 minutes into the game goalkeeper Unai Simon failed to control Pedri’s 49-yard back pass, presenting Croatia with the lead.
That bizarre own goal sparked a response from Spain though, with Pablo Sarabia thumping in an equaliser, Cesar Azpilicueta heading in another and Ferran Torres making it 3-1.
The thrilling moments continued as Simon made up for his earlier error with a heroic stop from close range to deny Andrej Kramaric before Morata went up the other end to crucially put Spain ahead again.
It was the most entertaining match of the tournament so far and three-time champions Spain will face the winner of France and Switzerland (kick-off 20:00 BST) in the quarter-finals.
Morata and Simon display Spanish character
Spain became the first side in European Championship history to score five or more goals in consecutive matches – but Morata’s was the most important.
The forward had missed several good chances in the tournament before this game and it looked like it would not be his night again when he failed to nod in Ferran Torres’ cross early on.
Two minutes later, that miss looked especially costly as Croatia took the lead – but it was Morata who the Spain players gathered to congratulate at full-time after their place in the quarter-finals was sealed thanks largely to his goal.
Spain’s credentials to go deep into the tournament have been enhanced by this display of character to initially bounce back from the own goal then re-gather themselves after Croatia had forced extra time.
The scenes at full-time were a mixture of jubilance and relief even if their biggest test may come next, with world champions France their potential quarter-final opponent.
There was nobody more relieved than keeper Simon too – he pulled off a crucial save in extra time after his huge error.
Croatia bow out – but not without fight
World Cup finalists Croatia lost at the last-16 stage for the second Euros in a row after they were beaten by eventual winners Portugal in 2016.
But they did not leave without a fight.
Nikola Vlasic smashed one into the side-netting and Kramaric was flagged offside as he snuck in behind before Spain went 3-1 up.
The substitutes forced extra time and Croatia could have gone ahead when Orsic fired dangerously over the bar minutes before Kramaric was denied by Simon.
Those misses proved costly and Spain almost scored a sixth when Dani Olmo’s curler smacked off the left post in the dying moments.
Croatia were naturally dejected at full time after they could not muster another astonishing comeback – but they had left their mark on this tournament by playing their part in an epic match.