The Liverpool flop's clever finish, coupled with Iran's late equaliser against Portugal means Spain finish top the group
Spain were staring a shock defeat to Morocco in the face before a dramatic leveller from substitute Iago Aspas.
The Liverpool flop's clever finish, coupled with Iran's late equaliser against Portugal means Spain top the group.
The 2010 champions now face Russia in the last 16 but they will have to improve on their performance here.
Fernando Hierro's side fell behind early on against Morocco after a defensive mix-up.
Sergio Ramos and Andres Iniesta didn't communicate and Khalid Boutaib took full advantage as he slotted his finish between the legs of David De Gea.
Spain hit back through Isco, who was their standout performer again, after excellent work from Andres Iniesta.
Iniesta picked out the Real Madrid star in the area and he lashed is finish into the top corner.
Both sides had chances to go ahead as Nordin Amrabat hit the bar before a dream moment for Morocco.
Youssed En-Nesyri rose high to head home a corner to leave Spain facing their first defeat in 23 matches.
But they were rescued by Aspas, whose clever finish looked to have been ruled out by the linesman's flag before VAR intervened.
Spain: De Gea, Carvajal, Sergio Ramos, Piqué, Alba; Busquets, Thiago (Asensio 74); Iniesta, Silva (Rodrigo 84), Isco; Diego Costa (Aspas 74)
Morocco: El Kajoui, Hakimi, Da Costa, Saiss, Dirar, Ziyech (Bouhaddouz 85), El Ahmadi, Belhanda (Fajr 63), Boussoufa, Amrabat, Boutaib (En-Nesyri 71)
- Iago Aspas90+1'
- Khalid Boutaïb14'
- Youssef En-Nesyri81'
The referee has awarded the goal! Dirar's leg plays Aspas onside and Spain have their equaliser.
Late, late drama at the Kaliningrad Stadium as Spain rescue a dramatic late equaliser, courtesy of an overturned offside decision via VAR. Morocco had restored their lead through En-Nesyri, who powered a wonderful header into the top-right corner following Fajr's delivery. Spain dominated possession throughout but it took until the 90th minute before they could find their breakthrough, with Aspas flicking Carvajal's pass beyond the reach of Mohamedi and into the far corner. Iran's late equaliser against Portugal means Spain go through as group winners and will face hosts Russia in the last-16 on Sunday.
Aspas saves Spain
FULL-TIME: SPAIN 2-2 MOROCCO.
They look to find the run of Rodrigo down the left channel but it is straight out for a goal kick.
It is all getting a little heated on the pitch now as we enter the sixth minute of added time. Spain have a free kick.
Hakimi receives a yellow card, likely for disputing the decision to allow Spain's goal.
Spain draw level!
Incredible scenes in Kaliningrad!
Spain have drawn level at the death.
Iago Aspas flicked the ball in but the linesman’s flag looked to have denied him.
But VAR intervened and the goal was given.
It all kicks off on the bench too but Spain have been saved.
Carvajal finds Aspas inside the box from the right and the Celta Vigo forwards draws Spain level again.
GOAL! Aspas makes it 2-2!!! The Spain substitute races onto a low pass from the right by Carvajal and cleverly flicks the ball beyond Mohamedi and in at the back post.
Spain have the ball in the back of the net but the linesman flag is up. It is going over to a VAR decision.
Spain will still qualify as runners-up despite facing defeat, with Portugal continuing to lead against Iran. This will still be a disappointing result for the Spanish though. The Morocco fans are in dreamland, the Atlas Lions have been outstanding today.
Mohamedi is booked for time wasting as he takes as much time as he can with a goal kick.
Spain have now conceded 12 goals in their last six World Cup matches, as many as their previous 18 combined.
Final change for Morocco as well as Ziyech is replaced by forward Bouhaddouz.
Silva comes off for Spain's third and final change. Rodrigo is on to replace him as Spain add more firepower in their bid to draw level once more.
Spain are pouring forward now as they desperately search for an equaliser. They have really struggled to create anything meaningful in this second half though. Morocco have been solid at the back.
Morocco back in front!
Morocco lead Spain again!
They have played very well here and it is a stunning header from Youssef En-Nesyri to put them 2-1 up.
If Iran level things up against Portugal, the 2010 champions will be in deep trouble!
Fajr's cross from the corner finds En-Nesyri in the centre of the box, who restores Morocco's lead.
GOAL! 2-1 Morocco!!!! It is a beautiful delivery by Fajr from the corner and substitute En-Nesyri rises highest to power an unstobble header into the top-left corner. No chance for De Gea and this Moroccan crowd are roaring.
CHANCE! A good low cross finds Ziyech inside the box. He volleys it goalward but it is blocked by Pique and out for a corner.
Just over 10 minutes to go and as things stand, Spain will finish as runners-up and face Uruguay in the last-16 on Saturday, with Portugal still leading Iran.
Morocco have a chance from the free kick, on the right wing. Poor delivery though and it is easily cleared at the edge of the box. They will need better quality than that if they are to break through this Spanish defence.
Costa is the first of a Spanish double change, as he is replaced by Celta Vigo forward Aspas.
Asensio is on as well, replacing Thiago in midfield.
Morocco finally find a way beyond the half line but concede a cheap free kick for a foul on Thiago. Spain substitution imminent.
Second change for Morocco as goalscorer Boutaib is replaced by En-Nesyri.
As he has been all tournament, Isco continues to be the creative driving force to Spain's attacks. He turns on the pace again to get beyond his marker and find Iniesta inside the box, who's cross is over the head of Costa and eventually cleared away by Hakimi. They are getting closer though.
Into the final 20 minutes here.
As things stand, Spain will finish second in the group with Portugal (who are beating Iran 1-0) in first place.
That means it will be Spain vs Uruguay and Portugal vs Russia in the last 16.
More impressive build up play from Spain. Costa lays the ball off into the path of Thiago, but the midfielder's side-footed shot curls high over the bar.
Iniesta and Isco have linked up wonderfully this evening and they do so again, with a quick interchange of passes causing trouble inside the box. Isco tries to put Iniesta through on goal but a defender does enough to see off the danger. Spain are turning up the heat.
Spain continue to probe but this time Alba is robbed of possession. Morocco tries to force an attack of their own but it comes to nothing. All Spain again now after that small spell of control from Morocco.
Belhanda becomes the first change of the game as Fajr comes on to replace him.
Substitution Younès Belhanda Fayçal Fajr
CHANCE! Spain finally break through the Morocco back line. Another excellent cross finds Isco at the back post but the midfielder's header is cleared off the line by Saiss. Excellent defending.
Cristiano Ronaldo had a chance to double Portugal's advantage but his effort from the penalty spot was saved by Alireza Beiranvand. It remains 1-0 to Portugal in that game, who will go through as group winners as things stand.
Spain have not had a shot on target since Gerard Pique's 23rd minute effort.
Despite all their possession, Spain have not really threatened Morocco in this half. The Atlas Lions are looking the better side in attack at the moment and are certainly going out of this tournament with a bang.
CHANCE! A swerving effort from the edge of the box by Amrabat strikes the underside of the crossbar and bounces out; much to the relief of De Gea, who was well beaten.
A cross from the set piece is easily claimed by Mohamedi. He releases the ball quickly and Morocco can break, but Spain get back in numbers quickly to quell the danger.
Hakimi tries to break forward from the left but he shows too much of it to Busquets. Spain try to exploit the space at the back but Another loose pass puts their attack to a tame end. Spain continue to dominate possession though.
CLOSE! A lovely chipped pass from the left wing puts Boutaib through on goal, but De Gea reacts quickly to clear the danger. Morocco have got in behind this Spanish defence on a number of occassions now with the long ball.
Spain are almost playing at walking pace at the moment. They are happy to just keep hold of the ball and invite Morocco onto them. Isco does try to speed things up a bit though but his heavy pass rolls straight back to an opposition player.
Morocco lose possession in their own half and Isco tries to find Iniesta with the through ball. The pass is a little too heavy though and it rolls out for a goal kick.
Morocco get the second half underway!
Andreas Iniesta is Spain's oldest ever player to deliver an assist at a World Cup (34y 45d).
Both sides will be happy with their display after that first half but Spain will surely up their game another gear in this second half. They cannot rely on the result at the Mordovia Arena to see them over the line. Morocco have proved to be a threat on the break though, so this could still go either way.
It is all square at the break of a competitive encounter, after Isco cancelled out Boutaib's opener after the Moroccan forward pounced on a communication mistake between Iniesta and Ramos. Spain dominated possession throughout but found Morocco's defence in a resolute mood, while Boutaib could have restored their lead were it not for a heavy touch on a rare breakaway chance. As it stands Spain will go through as runners-up, with Portugal leading at the break against Iran.
HALF-TIME: SPAIN 1-1 MOROCCO.
CHANCE! Beautiful footwork from Iniesta allows the veteran midfield to wriggle away from his marker and into the box. He fires a low pass across the face of goal but Costa is unable to get on the end of it.
Ricardo Quaresma has given Portugal the lead against Iran. As things stand, Spain will progress even if they lose here.
The fourth official has indicated two minutes of additional time.
Half chance for Morocco. Hakimi takes a touch on the edge of the box before firing a driven effort towards goal, which drifts just over the crossbar.
Morocco finally get a bit of breathing space and they can push out and put some pressure on Pique and Ramos. It pays off as well as Spain are forced to go long.
It's an excellent delivery towards the back post by Isco but Hakimi reads it well, getting ahead of Busquets to head clear.
Spain are totally dominating play now. They are moving the ball around the final third looking for an opening but the Moroccan defence are standing firm, before Isco is dragged down on the right wing. Set piece chance for Spain.
Isco has been the best player on the pitch...again.
The Real Madrid star picked out Alba with a delightful reverse pass a few moments ago.
The same cannot be said for Diego Costa, who has not been at it.
CHANCE! It is another wonderfully whipped delivery from a corner for Spain, this time towards the front post. Busquets meets it in the box, completely unmarked, but he can only head high over the bar. He should have done much better.
Since 1966, only Morocco in 1994 (five) have received more yellow cards in a first half of a WC game than they have so far today (four).
It remains goalless between Iran and Portugal so far, meaning that the Portuguese will advance alongside Spain as it stands. Still early doors though.
Boussoufa also receives a yellow card for dissent after disputing the booking of his teammate.
Another Moroccan booking as da Costa receives a yellow card for a needless lunge on Isco. Things are getting a little heated from a Morocco perspective. They are still well within this game though.
Spain level it up
Amrabat catches the heel of Ramos as he races onto a lofted through ball. The Madrid man goes to ground and Amrabat goes into the referee's book for the foul.
Spain have turned it up a notch here and are starting to find gaps in the Moroccan defence. A clever flick from Costa frees Isco on the left, but the midfielder's cross is cleared away at the back post by Saiss.
CHANCE! Boutaib races clear of the Spanish defence once again but a heavy touch inside the box takes him too close to De Gea, who smothers the shot. He is certainly proving to be a handful to this Spanish defence though, Boutaib.
Isco has been directly involved in 12 goals in his last 15 internationals for Spain (10 goals, two assists).
It is all Spain now as they win a corner on the left. The delivery finds Pique at the back post but the defender can not generate any power on his headed effort. Easy save for Mohamedi.
El Ahmadi is booked for a late challenge on Busquets.
Boutaib opens the scoring
Isco levels the scores
That is more like it.
Brilliant goal from Spain.
Isco starts the move by finding Costa, who picks out Iniesta.
The veteran playmaker brushes past his opponent to find Isco in the box.
He takes a touch to steady himself and lashes the ball into the top corner.
Iniesta finds Isco after a slick passing move for the Real Madrid midfielder to fire Spain level.
GOAL! Spain make it 1-1!!! Some wonderful quick football in and around the Morocco box frees Iniesta on the left. He reaches the byline before pulling the ball back towards the six-yard box, where Isco is on hand to smash the ball into the roof of the net.
Spain have it all to do now. A reminder that
LIVERPOOL have completed the world record £65m signing of Alisson from Roma. Alisson, 25, becomes Read More
Kylian Mbappe has been named as world football's most valuable under-21 star at a staggering Read More
The 33-year-old is the only player who wears a long-sleeved jersey in the Portuguese national Read More