Doha (AFP) - Achraf Hakimi struck the decisive penalty in a shootout to send Morocco into the World Cup quarter-finals for the first time on Tuesday as the African side stunned Spain after a goalless draw.
Spain coach Luis Enrique had claimed he set his players the "homework" of taking 1,000 penalties each.
But Pablo Sarabia, Carlos Soler and Sergio Busquets all missed from the spot before Madrid-born Hakimi dinked his home as Morocco won the shootout 3-0, to the delight of their raucous supporters.
Walid Regragui's side will face Portugal or Switzerland in what is uncharted territory for them -- their previous best run at a World Cup was a last-16 exit in 1986.
Spain had been hoping they could repeat their 2010 World Cup triumph after reaching the semi-finals of Euro 2020 last year, where they were also beaten on penalties by Italy.
Sevilla goalkeeper Yassine Bounou had other ideas and saved brilliantly from Soler and Busquets, while Sarabia hit the post from the spot.
"In football this is the best day of my life," said Morocco winger Sofiane Boufal.
"Today we made history.We can see the happiness of the people, of our family.
"Today is amazing, I can't describe it to be honest, the emotion.Today is historic."
Morocco topped their group after beating Belgium and drawing with Croatia, with Spain another scalp on a historic run.
The team have conceded just one goal, in a group stage win over Canada, and that tight defence kept Spain at bay.
The teams were closely matched throughout a tense game, with Spain having more of the ball but Morocco creating the better openings, few though they were.
The last African and Arab side left standing at the first World Cup held in an Arab country, Morocco were intensely backed and their fans greatly outnumbered Spain's.
With La Roja playing in a pale blue second strip, they resembled the away team on hostile territory.
Gavi, who at 18 years and 123 days old became the youngest player to start a World Cup knockout game since Brazil great Pele in 1958, rose to the occasion.
Regragui's side sat deep defensively, frustrating Spain, and threatened on the counter themselves.
"Nobody managed to steal the ball from them, so I accepted not having the ball," said Morocco coach Regragui."I'm not a magician."
Toothless Spain
Boufal, who bypassed Llorente with ease early on, carved the best chance of the half for Nayef Aguerd, who headed inches over.
Bounou pummelled away a Dani Olmo strike from an angle as the tension cranked up after the break.
Luis Enrique withdrew the dogged and muddied Gavi for Soler.
He threw Morata on too, giving Spain a focal point in attack, but they struggled to supply him as Morocco sat deeper and deeper.
Morocco were closest to scoring in extra-time, testing Simon, who made a fine save with his legs to deny Walid Cheddira after he broke down Spain's left flank.
Despite pressure from Spain in the final moments before penalties, they could not find a winner.
Having been sent on for the shoot-out, Sarabia struck the post from Spain's first penalty, after Abdelhamid Sabiri put Morocco ahead.
Soler and Busquets were foiled by Bounou, while Hakim Ziyech scored and Simon denied Badr Benoun, before Hakimi netted a chipped 'Panenka' penalty against the country of his birth to ignite wild celebrations.
"The penalties cost us but I am proud of my team," said Luis Enrique.
"I take all the responsibility because I chose the first three takers and the players decided the rest -- we didn't get to the fourth.
"Bounou is a great goalkeeper when it comes to penalties and today he was superb."