Achraf Hakimi calmly converted a penalty to send Morocco through to the World Cup quarter-finals for the first time with a 3-0 shootout win over former champions Spain after a cagey last-16 clash ended goalless on Tuesday.
Morocco goalkeeper Yassine Bounou saved spot-kicks from Carlos Soler and Sergio Busquets after Pablo Sarabia had hit the post and Spanish-born Hakimi held his nerve to earn his team a quarter-final against either Portugal or Switzerland.
Morocco became only the fourth African nation to reach the last eight of the tournament, 12 years after Ghana did so in South Africa.
After a scrappy match finished deadlocked at 0-0 after extra time with few shots on target, Morocco fed off the raucous support of their red-clad supporters in the shootout as Spain crumbled.
Spain enjoyed more than 75% of possession and completed almost 800 passes but Morocco caused problems for them on the counter-attack and goalkeeper Unai Simon made some good saves.
It was the fourth time Spain have been knocked out of the World Cup on penalties and the second in a row.
The Spanish spent big chunks of the match just orbiting around the Morocco penalty area without attempting any shots, through balls or moves to break down their well-organised opponents.
Morocco tried to use the pace of Hakim Ziyech and Soufiane Boufal and a foul on the latter gave the African side the first scoring opportunity as Achraf Hakimi blazed over a free kick.
Defender Nayef Aguerd headed over and Marco Asensio hit the side-netting for Spain.
Dani Olmo had Spain’s first shot on target in the 54th minute with an angled shot which Bounou palmed away.
Spain coach Luis Enrique sent on Alvaro Morata and Nico Williams to inject a bit of life into his team and Morocco had to dig deep to get through extra time without conceding.
They managed to do so and Spain's collapse in the shootout prompted wild celebrations among the Morocco supporters.