The Atlas lions have roared back for a 2-0 win to beat Ivory coast in Abidjan.
The last time Morocco qualified to the World Cup was in France 1998.
Morocco has the best defense in the world, as it is the only national team did not concede any goal during the World Cup qualifiers.
Morocco qualified for the first time since the 1998 World Cup.
While the Elephants will be left to rue a first World Cup qualifying failure since 2002, Morocco can now look forward to heading to Russian Federation as North Africa's third representatives alongside Tunisia and Egypt.
The Eagles of Carthage headed into their final fixture knowing that they would definitely reach the World Cup if they avoided defeat, but were frustrated by their neighbours.
Bapco: Saudi-Bahrain oil supplies resume
Bahrain said the explosion that caused a fire at an oil pipeline on Friday was an "act of terrorism" caused by sabotage. The explosion and fire hit near the village of Buri late on November 10, damaging nearby buildings.
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 could have been 3-0 up just seconds into the second half when Gbohouo made a hash of a cross, allowing the ball to fall to Mbark Boussoufa, whose goalbound effort was cleared off the line by Serge Aurier.
Nabil Dirar gave the visitors the lead 25 minutes in, cutting in from the right and seeing his left-footed cross go all the way in, raising serious questions over goalkeeper Sylvain Gbohouo.
Tunisia survived some nervous moments in Rades as Libya finished strongly.
The win takes Congo up to 13 points, but Libya's failure to beat Tunisia means they end the campaign tantalisingly one point short of the North Africans.
The Tunisians secured a fifth appearance at the tournament by topping the table with 14 points, one more than the Democratic Republic of Congo.