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 has revealed his family had been threatened during the tournament, 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, goalkeeper Unai Simon failed to control Pedri’s 49-yard back pass, presenting Croatia with the lead after 20 minutes.
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.
Spain looked comfortable and poised to cruise through but Croatia burst into action through their substitutes late on to force added time.
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 in the quarter-finals.