Spain went from the verge of elimination to winning Group B at the World Cup as VAR salvaged them a 2-2 draw with Morocco on Monday.
A feisty encounter saw Morocco take the lead twice through Khalid Boutaib and Malaga's Youssef En-Nesyri, but Isco wrapped up a slick move and Iago Aspas' last-gasp flick was correctly given by the video assistant, setting up a last-16 tie with hosts Russia.
Thiago Alcantara made his full debut in a major tournament for Spain as boss Fernando Hierro switched to a 4-2-3-1 formation, having tried out a 4-3-3 and 4-1-4-1 in his country's opening two games.
Elsewhere, it was as you were from the 1-0 win against Iran, with De Gea staying between the sticks, Dani Carvajal keeping his place at right-back and Diego Costa out to add to his tally of three goals.
Morocco, meanwhile, were already out of the World Cup, having lost to Iran and Portugal, but their preparations for the clash in Kaliningrad had been disrupted by internal issues.
Captain Medhi Benatia was seemingly benched for criticising his country's hierarchy after their 2-1 defeat to the Portuguese, while Getafe midfielder Faycal Fajr came under fire for using his phone during a training drill.
This was the first meeting between Spain and Morocco, while La Roja were top of Group B by the virtue of having received fewer yellow cards than their Iberian neighbours.
Gerard Pique was a lucky boy early doors as he lunged through Khalid Boutaib with his studs up but avoided even a talking-to.
However, La Roja weren’t so when a huge mix-up near the halfway line between Andres Iniesta and Sergio Ramos released Boutaib away in the clear, the striker going on to curl a finish through David de Gea’s legs.
Iniesta redeemed himself for his earlier mistake, getting to the byline in Morocco’s box from a free-flowing move, before cutting back for Isco, who smashed a finish into the roof of Munir El Kajoui’s net.
Yet Pique and Sergio Ramos were guilty of another Spanish misjudgement as their failure to read a throw-in allowed Boutaib to sneak in behind again. This time, however, De Gea stopped the striker one-on-one.
The North Africans threatened to lose their heads, picking up four yellow cards in the first half-hour, but as news of Cristiano Ronaldo missing a penalty for Portugal filtered through, former Leganes loanee Nordin Amrabat blasted an unstoppable drive on to the post.
At the other end, Isco guided a header towards the top-right corner of Munir’s goal, but Wolverhampton Wanderers’ Romain Saiss was there to nod it away from the Moroccan net. Pique then brushed the wrong side of the post from the resulting corner with a header.
Hierro waited until the 74th minute to throw on Marco Asensio and Aspas, yet Herve Renard had a trick up his own sleeve, introducing En-Nesyri, who outjumped Ramos from a corner and crashed a header into the back of De Gea’s net.
Iran also equalised in their game against Portugal, but Aspas came up trumps for Spain right at the death as VAR was on hand to let his flick from a corner stand.
The 2010 champions are next in action on Sunday, when they lock horns with Russia in the first knockout stage.
Spain 2-2 Morocco
Isco 19, Aspas 90 (S) Boutaib 14, En-Nesyri 81 (M)
Spain: De Gea; Carvajal, Pique, Ramos, Alba; Busquets, Thiago (Asensio 74); Silva (Rodrigo 84), Iniesta, Isco; Costa (Aspas 74)
Morocco: Munir; Achraf, Da Costa, Saiss, Dirar; El Ahmadi, Boussoufa; Amrabat, Belhanda (Fajr 63), Ziyech (Bouhaddouz 85); Boutaib (En-Nesyri 71)
Referee: Irmatov (UZE)