Hakim Ziyech scored in the first half as Morocco beat Zambia 1-0 on Wednesday at the Africa Cup of Nations finals to finish top in Group F and also keep hosts Ivory Coast in the tournament.

Morocco’s stand-in captain left the pitch with an ankle injury at halftime but not before a smart close-range finish in the 38th minute lifted Morocco to seven points, ahead of second-placed Democratic Republic of Congo, who drew 0-0 with Tanzania.

Zambia finished third in the group on two points, which was not enough to take one of the four places in the last-16 reserved for the best third-placed finishers.

Instead the Ivory Coast sneaked in, sparking celebrations in the Laurent Pokou Stadium from locals who had come to support Morocco knowing that if Zambia lost, their team would qualify.

Their reward, however, is a meeting in the last-16 on Monday with holders Senegal, who were the only side to win all their group games. The Ivorians will have a new coach in Emerse Fae who takes over from Jean-Louis Gasset, who was fired on Wednesday.

Morocco’s victory was deserved despite them changing much of their lineup, resting key players, and being without coach Walid Regragui, who was banished to the stands after the Confederation of African Football suspended him hours before kickoff.

He received a four-match ban, two of which were suspended, after being involved in an on-field spat with DR Congo captain Chancel Mbemba at the end of their match in San Pedro on Sunday, which then led to scuffles between opposing players and staff on the pitch and alleged fighting in the tunnel at the stadium.

Zambia’s key striker Patson Daka had an early chance but failed to control a clever ball over the top of the Morocco defence before the World Cup semi-finalists took over and dominated proceedings.

There were chances for Ismael Saibari and Nayef Aguerd before Ziyech reacted quickest and hit home a rebound after a build-up involving Saibari and Achraf Hakimi.

Ayoub El Kaabi had a strong effort saved two minutes after Ziyech’s goal and Saibari was denied from a good opportunity two minutes into the second half.

Zambia’s best opportunity for the draw they needed to advance came when Lameck Banda snapped an effort narrowly wide in the 59th minute.

Morocco now meet South Africa in San Pedro in the last-16 next Tuesday while DR Congo are up against Egypt on Sunday.