Spain recovered from a bizarre own goal and a barnstorming Croatia fightback to reach the Euro 2020 quarter-finals with a dramatic 5-3 extra-time victory on Monday.
Goals from the much-maligned Alvaro Morata and Mikel Oyarzabal finally settled an eventful contest in Copenhagen that ended 3-3 after 90 minutes.
Croatia had taken an unexpected early lead when Spain goalkeeper Unai Simon allowed a backpass from Pedri to squirm into the net.
Spain responded superbly through Pablo Sarabia, Cesar Azpilicueta and Ferran Torres but Croatia hit back with two goals in the last five minutes of normal time from substitutes Mislav Orsic and Mario Pasalic.
Croatia carried their momentum into extra time but Simon made a fine save and Spain ultimately went on to secure a place in the last eight.
Spain, who beat Slovakia 5-0 in their final group match. made a positive start. Sarabia shot into the side-netting and Koke should have scored when he was denied by the feet of goalkeeper Dominik Livakovic.
Morata's frustrations then continued as he spurned a fine chance by miscuing a header.
Croatia were offering little but, remarkably, found themselves in front after 20 minutes.
It came in extraordinary circumstances as Simon switched off. Pedri passed the ball back from near the halfway line and the keeper took his eye off it as it bobbled, caught his foot and rolled into the net.
It was a moment to forget but Spain responded well to the setback and levelled before the break.
Livakovic did well to save a well-struck shot from Jose Gaya but Sarabia was on hand to tuck home the rebound, albeit with the aid of a deflection.
The Spanish then appeared to be taking a firm grip as they claimed the lead 12 minutes into the second half through Azpilicueta.
The Chelsea captain got himself into an advanced position as Pedri brought Spain forward. Manchester City's Torres then whipped in a fine cross from the left and Azpilicueta rose at the back post to power home a header.
Torres appeared to have given Spain a firm grip when he shrugged off a defender to expertly clip home a third goal 14 minutes from time.
Croatia, however, were not beaten and roused themselves in a grandstand finish.
They got themselves back into the game as Orsic got the final touch to pull one back in a goalmouth scramble.
Orsic was then involved again as Croatia grabbed a dramatic injury-time equaliser, swinging in a cross from the left which Pasalic met with a firm header to beat Simon.
Spain appeared deflated and were almost caught out early in extra time but Simon, atoning somewhat for his earlier error, made a superb save to deny Andrej Kramaric at point-blank range.
Buoyed by that, Morata then delivered a strong riposte to his critics by firing Spain into a 4-3 lead with a ferocious strike into the roof of the net in the 100th minute.
Moments later, Spain had a two-goal lead again as substitute Oyarzabal raced into the box to meet a fine ball from Dani Olmo and tuck home.
In keeping with a frantic game, Ante Budimir could have replied for Croatia but missed the target when well placed.
Olmo also hit the post as Spain continued to threaten until the end in an entertaining encounter.