Fenerbahce winger Nabil Dirar put Morocco ahead on 25 minutes when his cross from the right dropped into the Ivory Coast net, before captain Medhi Benatia swiftly doubled the lead on the half-hour following a corner.
Morocco and Tunisia have joined Nigeria, Egypt, and Senegal as the African teams who will be playing in the World Cup this summer.
Morocco sealed its place by winning in Ivory Coast 2-0 in what was a straight shootout for the place from Group C.
Libya had been forced to play all of their home games at neutral venues, including Tunisia, because of a Federation Internationale de Football Association ban on internationals in the country, where the security situation is judged unsafe for visiting teams.
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.
The Atlas Lions are returning to the World Cup for the first time in 20 years after they last made it in 1998.
Tunisia last played at the World Cup in 2006.
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.
Tunisia, meanwhile, progressed as winners of Group A despite not being able to end their campaign with victory over Libya, who finished bottom.
DR Congo defeated Guinea 3-1 but that did not matter as Tunisia had secured a point.
Morocco have remarkably qualified from Group C without conceding a single goal.