Morocco beat Cote d'Ivoire 2-0 away in their final group game while Tunisia's 0-0 home draw against Libya was enough to seal their qualification.
Both nations join Nigeria, Egypt and Senegal, as Africa's representatives at the global finals next year.
Morocco returns to the world's biggest stage for the first time since 1998.
The qualification, which came 19 years since Morocco played its last World Cup in 1998 in France, has enabled the Atlas Lions to retrieve their lost aura and respectability in Africa.
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 is back in the spotlight of world soccer following the qualification of the country's national team to the 2018 World Cup, scheduled to take place next summer in Russian Federation. Before today's matches, Morocco had 9 points while the Ivorians had 8 points; meaning the victor of the match would qualify.
It was to prove a costly miss for the home side, who had to win after beginning the match one point behind a Moroccan team coached by former Ivorian handler, Frenchman Herve Renard.
Nabil Dirar scored the opener in the 25th minute with an inswinging cross that went untouched through the box and entered the net.
Tunisia survived some nervous moments in Rades as Libya finished strongly.
Morocco needed only a draw from their final Group C game to finish top of the standings in the African preliminaries, ahead of the Ivorians, who had to win to clinch a fourth successive World Cup finals appearance.