Neither team was able to break the deadlock for the first 45 minutes at Doha's Education City Stadium.
Despite several efforts from both sides in the second half, neither national team was able to produce a goal as the match went to extra time.
The extra time in the Round of 16 match was 0-0. So, the penalty shootout decided the winning team.
Abdelhamid Sabiri, Hakim Ziyech, and Achraf Hakimi converted their spot kicks against Spain during the penalty shootout. Badr Benoun missed his penalty for the Atlas Lions.
Spain's Pablo Sarabia, Carlos Soler, and Sergio Busquets failed to convert from the penalty spot.
Morocco will face the winner of the Portugal vs. Switzerland match in the next stage.