Sofiane Boufal and Abdelhamid Sabiri scored to give Morocco a 2-1 victory against Brazil in Tangier.
It was Morocco's first ever victory against the five-time world champions.
Morocco delivered a statement win against soccer powerhouse Brazil in their first home game.
The match almost turned into an ill-tempered affair, with Brazilian players complaining bitterly to the referee.
Brazil controlled possession while Morocco were always dangerous in the counter-attacks.
Palmeiras winger Rony missed a sitter from close range in the 13th minute.
Goalkeeper Yassine Bounou almost gifted Brazil a goal in the 22th minute with a comical mistake.
Morocco scored first after Bilal El Khannous assisted Sofiane Boufal to score from close range.
Brazil found the equalizer in the 67th minute thanks to a schoolboy mistake by Bounou.
Morocco hit back 12 minutes later with substitute Abdelhamid Sabiri's unstoppable strike.
Morocco became the first Arab team to reach the quarterfinals and the first African team to make the semis.