Spain will play Russia in the last 16 of the World Cup, but needed a lot of luck and a major moment of video assistant referee drama to seal top spot in Group B. Late goals in both games meant Portugal and Spain both drew their final group games, with La Roja's goals scored tally the only thing deciding which Iberian side finished first.
Spain's defence looked shaky throughout, playing very high up the pitch, and often with all 10 outfield players in the Morocco have, they were always susceptible to counter-attacks. It was a combination of this space in behind and poor play from Andres Iniesta that gifted Morocco the opener. The former Barcelona midfielder got his wires crossed with Sergio Ramos, leaving Khalid Boutaib the freedom to run half the length of the pitch with the ball and slot it past David de Gea - his fourth goal conceded in this tournament without having made a save.
De Gea finally made his first stop of the tournament to deny Morocco the chance to go back in front following Spain's well-worked equaliser. A clever throw-in found Boutaib in behind the defence again, but he overplayed it before shooting straight at the Manchester United stopper.
Isco was central to everything positive Spain did, playing a one-two with Diego Costa in the build up to his own fine finish, as well as having a header cleared off the line as Spain pushed hard to go ahead in the game and the Group B standings.
The Real Madrid midfielder repeatedly demanded the ball from team-mates, dropping into space, found holes to exploit and tried to play the ball into team-mates like when he took a deft touch to confuse a defender before putting David Silva through, only for the Manchester City man to lose his footing.
Morocco's frustrations with Isco's penetration grew evident as the second-half wore on, deciding to foul him rather than letting him carry the ball further up the field and cause more problems. Spain were unable to eradicate their own problems at the back, with Nordin Amrabat hitting the crossbar with De Gea well beaten. The goalkeeper could also do little about Morocco's second, coming from a corner with Youssef En-Nesyri jumping well above Sergio Ramos to head home.
Ramos' centre-back partner Gerard Pique was comfortable in possession and played better defensively than the team captain, but easily could have found himself off the field for a two-footed challenge in the first-half that strangely went unpunished.
The best defender on the field was a Real Madrid player, but not one who plays for Spain at international level. Achraf Hakimi only played seven La Liga games in 2017-18, but the 19-year-old was cool and confident on and off the ball and even left Dani Carvajal on his backside with a clever trick in the first-half.
Spain were given a lifeline through VAR which overturned the referee's decision to rule out Iago Aspas's header from Isco's cross. After reviewing the footage, the subsitute was shown to be onside and the goal was given.
Morocco's bench poured onto the pitch in outrage before the game was restarted. While all the drama was happening in Kaliningrad, similarly crazy scenes broke out in Saransk, where Iran equalised from the penalty spot to miraculously put Spain top of the group.
Russia were the favoured opponent in the next round, with the late, late drama in both matches ensuring that Spain avoided Group A winners Uruguay and now face the hosts in Moscow on July 1.