The Spaniards were unable to score a single penalty in the shootout, with the first penalty taken by late substitute Pablo Sarabia, who hit the post after the Moroccans cooly slotted in their first.
Hakim Ziyech went on to score Morocco’s second penalty with Moroccan keeper “Bono” saving Spain’s second penalty effort. The Moroccans then missed their third penalty thanks to an Unai Simon save, giving the Spaniards a ray of hope.
The Spanish captain Sergio Busquets, who could well have been playing his last match for Spain, then had his penalty saved, leaving the Moroccans needing just one more to go through.
Madrid-born Achraf Hakimi stepped up calmly and sent Spain packing with a steely ‘”panenka” to send the Moroccans to the quarter-final – a first for any Arab nation.
It was the first penalty shootout that Morocco has ever taken part in at a World Cup.
Earlier, the match went to extra time with very little separating the former world and European champions, Spain, from the 22nd-ranked Morocco.
Morocco created their best chance in the first half of extra time, nearly slotting home in the 13th minute, only to be denied by a save from the Spanish keeper Unai Simon.
Regulation time was equally fraught, with both teams evenly matched throughout both halves and both teams coming close on several occasions, but neither side proving decisive.
The Spaniards hit the upright with the last attack of the second half in extra time, sending the match into a penalty shootout – the second one after Monday’s shootout between Japan and Croatia.
Morocco is the first team from the Middle East and North Africa to make it to the quarter-finals since Turkey made the semi-final in 2002.
Before this World Cup, Morocco had only won two out of 15 games across five World Cup tournaments, against Scotland in 1998 and Portugal in 1986, the year the Atlas Lions made it out of the group stages for the first time.
Morocco was the only team from the Middle East and North Africa to make the last 16, after Qatar, Iran, Tunisia and Saudi Arabia were eliminated during the group stages.
In the group stages, following a spirited goalless draw against Croatia, the Atlas Lions pulled off a stunning 2-0 victory over Belgium, ranked world number two, in a pulsating match at Al-Thumama stadium. They wrapped up first place in Group F with a convincing 2-1 win over Canada.
Morocco will play the winner of the Portugal-Switzerland match in the quarter-finals.