Spain crashed out of yet another major tournament on penalties thanks to Madrid-born Achraf Hakimi’s perfect Panenka.
Pablo Sarabia, Carlos Soler and Sergio Busquets all missed their spot-kicks for the 2010 champions as Morocco made history by reaching the World Cup quarters for the first time.
Luis Enrique’s Spain meanwhile have now been knocked out of the last three international competitions from 12 yards – including the 2018 World Cup and last summer’s Euros.
Moroccan keeper Yassine Bounou was the hero – saving two while the other smacked his left-hand post, and was held aloft by his jubilant team-mates at the end.
And PSG full-back Hakimi then stepped up to score the winner with an outrageous dink down the middle of the goal to leave Unai Simon red-faced.