Hakim Ziyech scored to give Morocco a 1-0 Africa Cup of Nations Group F win over Zambia on Wednesday -- a result that enabled hosts Ivory Coast to scrape into the last 16.
The Ivorians, humbled 4-0 by Equatorial Guinea on Monday, were among the four highest-ranked third-placed teams who qualified.
Group winners Morocco will face South Africa in the round of 16 while runners-up the Democratic Republic of Congo, who drew 0-0 with Tanzania, face Egypt.
Morocco coach Walid Regragui watched the match from the stand after being banned for two matches following a post-match clash with DR Congo captain Chancel Mbemba on Sunday, AFP reported.
Regragui entered the pitch after a 1-1 draw and appeared to have strong words with Mbemba, while also attempting to shake hands. The two men then had to be separated by several people.
The Royal Moroccan Football Federation said they will appeal the suspension, calling it an "incomprehensible decision (as) Regragui did not... contravene the spirit of fair play".
Morocco were playing their 73rd match and Zambia a 70th in the flagship African competition, but this was only the third time they have met with the Atlas Lions previously winning and drawing.
Captain and defender Romain Saiss was rested by the shock 2022 World Cup semi-finalists and forward Youssef En-Nesyri started on the bench.
With Zambia captain Roderick Kabwe suspended, recalled Lubambo Musonda led Chipolopolo (Copper Bullets), and regular starters Fashion Sakala and Kings Kangwa were among the substitutes.
Morocco began the final round group match already assured of a last-16 place while Zambia had to at least draw to squeeze through at the expense of Ivory Coast.
As anticipated, a Moroccan team ranked number one in Africa quickly established control of territory and possession in the southwestern coastal city.
Zambia survived a number of scares before finally falling behind after 38 minutes in a stadium named after deceased Ivorian football legend Laurent Pokou.
Goalkeeper Lawrence Mulenga spilled a cross from Achraf Hakimi and Ziyech reacted quickest in the goalmouth and slammed the loose ball into the net.
Moroccan winger Sofiane Boufal was lectured by the Gabonese referee soon after for diving in the area, seeking a penalty.
Ziyech, on loan to Istanbul outfit Galatasaray from Chelsea, did not reappear for the second half due to an injury and was replaced by Amine Adli.
With 20 minutes remaining, Zambia coach and former Chelsea and West Ham United manager Avram Grant introduced Sakala and Kangwa, hoping they could boost chances of an equaliser.