Unbeaten Tunisia collected 14 points to book a first World Cup appearance since 2006, DR Congo had 13, Libya four and Guinea three.
Before Saturday, the trio of Nigeria, Egypt and Senegal had booked their tickets before the two North African countries also came on board to Russian Federation.
It is another achievement for Morocco's French coach Herve Renard, who famously won the Africa Cup of Nations with Ivory Coast in 2015.
West Africa has dominated Africa's contingent at the World Cup in recent years but some of its big names missed out this time: Ivory Coast, Cameroon and Ghana, all African champions multiple times, won't be in Russian Federation.
Morocco return to the world's biggest stage for the first time since 1998.
Following a shock defeat to Gabon in Group C, the Ivorians had to win to reach a fourth straight World Cup.
Despite needing only a point to qualify, the Atlas Lions weren't prepared to sit on a slender lead and doubled their advantage five minutes later when former Bayern Munich center back Medhi Benatia turned in a left wing corner.
Cote d'Ivoire needed an outright win to qualify while a draw would still have been enough for Morocco.
Dirar's in-swinging cross beat everyone and found the corner of the net in the 25th minute.
Tunisia emerged the leaders in Group A, surviving a resilient Libya that shared the spoils of the day with their hosts. Had Tunisia lost, the two teams would have finished level on points and goal difference and Congo would have taken the World Cup place for scoring more goals in the qualifying campaign.