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.
The Spanish-born Hakimi chipped in the decisive penalty, prompting a deafening roar of joy and celebration from the Morocco supporters, after their side became the first Arab nation ever to qualify for the tournament's quarter-finals.
Morocco goalkeeper Yassine Bounou, who plays for Spain's Sevilla, saved spot-kicks from Carlos Soler and Sergio Busquets after Pablo Sarabia had hit the post and Hakimi, a product of the Real Madrid youth system, 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 0-0 after extra time with few shots on target for either side, Morocco fed off the raucous support of their red-clad fans in the shootout as Spain crumbled.
Spain enjoyed more than 75 per cent of possession and completed almost 1000 passes but Morocco caused problems for them on the counter-attack and goalkeeper Unai Simon made some good saves.
"We fought and made the Moroccan people happy, we made history and Morocco deserve it, Moroccan people made us united on the pitch," coach Walid Regragui said.
Morocco defender Jawad Yamiq was proud of his team's performance.
"We honoured the Arab and African football, coach Regragui gave us the confidence that we needed in this game, a big boost in morale," he said.
"We knew that Spain depend on their ball possession and we played with that in mind. They didn't impose any danger."
It was the fourth time Spain have been knocked out of the World Cup on penalties and the second in a row.
It was a huge blow for Luis Enrique's team, who arrived in Qatar as one of the favourites after reaching the Euro 2020 semi-finals and the Nations League final last year.
"We completely dominated the match, it's a shame it went that way," the Spain coach told TVE.
"It's the most difficult thing, playing against a team like Morocco who are hard workers.
"The penalties cost us, but I am very proud of the team and all the players. I’m very sorry about the result but I congratulate Morocco."
Spain spent big chunks of the match orbiting around the Morocco penalty area without attempting any shots, through balls or moves to break down their well organised opponents.
They tried to play the possession-style game that was the trademark of the great Spanish sides who won two European Championships and the World Cup between 2008 and 2012.
But they lacked a cutting edge and Morocco allowed them possession while trying to exploit the pace of Hakim Ziyech and Soufiane Boufal.
A foul on the latter gave the African side the first scoring opportunity as Hakimi blazed over a free kick.
In a tight first half, the only other chances came when 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.
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 ecstatic Morocco supporters who will get at least one more chance to make their presence felt in Qatar.