The result also kept hosts Ivory Coast in the tournament.
However, star man Hakim Ziyech was forced off at half-time with an ankle injury, minutes after scoring the opener. Morocco's stand-in captain left the pitch with an ankle injury at half-time 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.
The knockout stage begins on Saturday.