Morocco scored twice within five minutes through Nabil Dirar and Medhi Benatia during the opening half to triumph 2-0 in the Ivory Coast and win Group C.
The “Atlas Lions” are going back to the tournament for the first time since 1998 after finishing with 12 points, having not conceded a goal during the six-match mini-league campaign.
Ivory Coast, who never looked like recovering from the first-half blows, came second with eight points followed by Gabon with six and Mali with four.
Tunisia could not break down neighbours Libya in Rades on the outskirts of Tunis and had to settle for a 0-0 draw that was just enough to see them first over the finishing line.
With second-place Democratic Republic of Congo netting twice in stoppage time to defeat Guinea 3-1 in Kinshasa, only one point separated the top two.
Unbeaten Tunisia collected 14 points to book a first World Cup appearance since 2006, DR Congo had 13, Libya four and Guinea three.
Senegal sealed a place in Russia Friday by winning 2-0 in South Africa and the other two African qualifiers, Nigeria and Egypt, won their groups last month.