The result took them up to 12 points, four clear of the Ivorians in second place, confirming their return to the World Cup for the first time since 1998, when they were eliminated in the group stage.
Tunisia qualified for the World Cup after winning the group with 14 points.
The 2004 African champions have now qualified for their fifth World Cup (1978, 1998, 2002, 2006).
Tunisia guaranteed top spot in World Cup qualifying Group A and secured their ticket to Russian Federation despite being held 0-0 at home by Libya on Saturday.More news: Hasbro Makes Bid For Rival Toymaker Mattel
The hosts poured men forward for most of the rest of the match, but Morocco generally looked in control of things at the back and held on comfortably, giving Herve Renard - the coach who ended Ivory Coast's Africa Cup of Nations drought in 2015 - a famous victory against his former team.
Nigeria were the first African nation to book a place in Russian Federation after last month's 1-0 win over Zambia in Uyo with Egypt and Senegal, who beat South Africa 2-0 in a replayed game in Polokwane on Friday, having also qualified.
The first blow came when an intended cross from Dirar went over an Ivorian defender and a Moroccan attacker and slipped past goalkeeper Sylvain Gbohouo into the far corner.
Two stoppage-time goals through Jonathan Bolingi and Neeskens Kebano, which sealed a 3-1 win against Guinea, was not enough for Florent Ibenge's side, who needed Libya to record a victory over the Eagles of Carthage on Saturday.
Tunisia booked their place in next year's World Cup finals after securing a point from a goalless draw at home against their neighbors Libya.