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 it on the counter-attack and goalkeeper Unai Simon made some good saves.
It was the fourth time Spain has been knocked out of the World Cup on penalties and the second in a row.