Substitute Iago Aspas scored in stoppage-time to earn Spain a dramatic 2-2 draw with Morocco on Monday and World Cup Group B top spot for a place in the last 16.
With Morocco heading towards their first win of the tournament, Aspas delivered the late heroics when he back-heeled the ball into the net.
It canceled out Youssef En-Nesyri’s brilliant 81st minute header for Morocco.
The Spanish goal was however awarded after a lengthy review by the Video Assistant Referee.
Spain thus grabbed 2018 FIFA World Cup Group B top spot from Portugal on account of goals scored after the European champions were held to a 1-1 draw by Iran.
Morocco, who were the first team eliminated from the World Cup following two 1-0 losses, began to play with intensity.
It was an indicated that they had every intention of returning home with a Spanish scalp, and Khalid Boutaid duly put them ahead in the 14th minute.
Snatching the ball from Sergio Ramos in midfield Boutaid ran through alone and coolly slotted home between the legs of David de Gea for Morocco’s first goal of Russia 2018.
With a last-16 spot on the line, the goal shocked Spain into action and Isco equalised for the 2010 world champions five minutes later.
He picked up Andres Iniesta’s pass and crashed it into the roof of the net.
Spain nearly grabbed a second just before halftime when Iniesta fired a low pass across the goalmouth, but a sliding Diego Costa just missed getting his foot to it.
Morocco returned to the pitch with renewed purpose after the break, taking the play to Spain.
Nordin Amrabat nearly gave the North Africans the lead in the 56th minute when his thunderbolt from 25 yards clanged off the far post and crossbar.
It was Spain’s turn to go close next as Morocco defender Romain Saiss cleared Isco’s header off the goalline.
After En-Nesyri’s brilliant 81st minute header, Spain finally began to play with urgency especially as time was running out, but they could not find the equaliser.
It was not until Aspas struck, and his goal was finally given after a long wait for VAR confirmation.
Spain will now face in the last 16 hosts Russia, who were runners-up from Group A, having topped their group ahead of Portugal who also have the same five points.
Goals scored was used to determine group winners after both sides ended up with the same number of points after one win and two draws from three matches each.
The 2010 World Cup winners emerged tops on the basis of scoring six goals, while Portugal scored five.