Luis Enrique, who went with Marcos Llorente at right-back, saw his side have 70 per cent possession in the first-half but create few chances in a largely dull 45 minutes.
Available on Eurosport app. Subscription and Internet connection required. Age 18+. T&Cs apply.
They had a bright three minute spell with Gavi hitting the crossbar after a mistake at the back, but an offside flag was raised, and Marcos Asensio smashing a shot into the side-netting but for the most part the North African side defended well.
Morocco rarely ventured forward but should have broken the deadlock when an unmarked Nayef Aguerd headed over the bar from close range.
The second-half had much of the same disjointed play which led to Alvaro Morata and Carlos Soler coming on around the hour mark while Abde Ezzalzouli came on for the Atlas Lions.
But it failed to yield a goal with Morata wastefully heading over in the last minute from a Soler freekick.
In extra time, Walid Cheddira spurned two big chances to score. Aymeric Laporte got back to nick the ball away after the striker took too long to shoot and minutes later he shot straight at Unai Simon.
Enrique’s side were largely wasteful in the final third but could have nicked it in the dying seconds when Pablo Sarabia’s volley from a tight angle hitting the post.
In the shootout, Sarabia hit the post, Soler’s tame effort was saved and Sergio Busquets missed his spotkick.
And Madrid-born Achraf Hakimi converted his penalty to send Morocco through to the quarter-finals.
Developing story…