Morocco's hopes of a first Africa Cup of Nations title in 48 years were dashed by South Africa on Tuesday night after falling to a 2-0 defeat in San Pedro.
Evidence Makgopa and Teboho Mokoena scored in the second half for South Africa, who once again proved a bogey team for the Morocco, who saw Achraf Hakimi miss a late penalty to equalise and had Sofyan Amrabat sent off in injury time.
Since becoming the first African side to reach the World Cup semi-finals in Qatar two years ago, Morocco have lost just two of 13 matches, and both defeats were inflicted by South Africa.
The shock last 16 result in the Ivory Coast coastal city of San-Pedro came after Mali overcame Burkina Faso 2-1 in Korhogo with Lassine Sinayoko scoring what proved the key goal.
Morocco join defending champions Senegal, Tunisia, Algeria, Cameroon, and Burkina Faso as teams ranked among the top 10 in Africa heading home early.
On Saturday, South Africa will face Cape Verde in Yamoussoukro after hosts Ivory Coast and Mali clash in Bouake.
In the other quarter-finals, Victor Osimhen-inspired Nigeria face Angola and the Democratic Republic of Congo meet Guinea on Friday.
South Africa, Ivory Coast, Nigeria and DR Congo are former champions while the other four title contenders are hoping to conquer Africa for the first time.
While Morocco, thanks to their World Cup heroics, were favoured to eliminate South Africa, two factors suggested there was a chance of a shock.
South Africa had won two and drawn two of five previous Afcon meetings with Morocco from 1998. And despite being an African powerhouse for decades, Morocco have consistently fallen short at the tournament since their lone triumph in 1976.
Coach Walid Regragui called the repeated failures an "African curse" and the former national team full-back saw clinical South Africa pull off a deserved victory.
Makgopa stayed just onside to fire South Africa in front on 57 minutes and Morocco squandered a great late chance to equalise when Hakimi fired a penalty against the crossbar and over.
A foul on Mokoena by Manchester United midfielder Amrabat led to a VAR review that ended with a straight red card as he was the last defender.
Set-piece specialist Mokoena fired the free-kick past Yassine Bounou and high into the net at the near post.
Mali into quarter-finals
Lassine Sinayoko scored his third goal at Afcon as Mali reached the quarter-finals for the first time since 2013 by defeating Burkina Faso 2-1 in Korhogo earlier on Tuesday.
An early Edmond Tapsoba own goal got Mali off to a great start in the last 16 tie and Sinayoko doubled the lead just after half-time.
Captain Bertrand Traore reduced the arrears from a penalty for Burkina Faso, who had the ball in the net again only for Issoufou Dayo to be ruled offside.
Victory was a welcome change of fortune for Mali, who have had two first-round and two last-16 exits since finishing third in South Africa 11 years ago.
"It was a really tough match against a good side. We had to work extra hard, but I am glad we eventually got the result," said Sinayoko.
"We can celebrate this victory while keeping at the back of our minds that there is still a lot of work ahead."
The match in the northern Ivorian city kicked off in 36 degrees Celsius heat and Mali needed only 133 seconds to score the second-fastest goal in the tournament.
A powerful Amadou Haidara header off a cross rebounded off the post, struck the left foot of Tapsoba and rebounded into the net for an own goal.
Mali went two goals ahead two minutes into the second half as Sinayoko broke clear of Tapsoba and beat goalkeeper Herve Koffi with an angled shot.
But the lead was halved on 57 minutes when Boubakar Kouyate handled a cross and Traore converted his third penalty of the tournament as Mali goalkeeper Djigui Diarra dived the wrong way.
Long-serving defender Issoufou Dayo thought he had levelled in the final minute of regular time by heading a free-kick past goalkeeper Djigui Diarra but was ruled offside.