Youssef En-Nesyri scored the only goal of the game as Morocco beat Ivory Coast 1-0 to qualify for the last 16 at the Africa Cup of Nations.
En-Nesyri struck in the 23rd minute as Morocco followed up their opening defeat of Namibia with another narrow victory at Al Salam Stadium on Friday.
A second successive 1-0 win for Herve Renard's men means their place in the next round is secure, while Ivory Coast will need a result in their Group D closer against Namibia.
Romain Saiss made a superb goal-line clearance to deny Jonathan Kodjia in the opening minute, but it was Morocco who took a first-half lead.
Nordin Amrabat collected a cross-field pass, brilliantly jinked inside a series of challenges and slipped the ball through to En-Nesyri, who made no mistake with a low finish.
Ivory Coast sought an immediate reply but, after Yassine Bounou was quickly off his line to keep out Max Gradel, Nicolas Pepe could only find the side netting from the edge of the box.
Wonlo Coulibaly delivered a fine left-wing cross for Kodjia in the 62nd minute but the striker, who netted his side's winner against South Africa, failed to hit the target.
As the Elephants left gaps at the back, Morocco pushed for a second and En-Nesyri went close with a glancing header.
Ismael Traore's ambitious overhead kick was straight at Bounou as Ivory Coast pressed desperately for a leveller, but Morocco should have had a second in added time when Noussair Mazraoui volleyed against the crossbar from close range.