The Super Eagles broke the deadlock against the Panthers at the Moulay Hassan Stadium through Akor Adams after 78 minutes.
Mario Lemina levelled the score with his goal on 89 minutes to take the tie to extra-time.
Chidera Ejuke then gave Nigeria a 97th minute advantage and Victor Osimhen sealed a 4-1 result with two late goals after 102 and 110 minutes.
In the other World Cup qualifying play-off semi-final tie, DR Congo defeated Cameroon 1-0 with a 91st minute goal from defender Chancel Mbemba.
The Leopards captain was well placed to convert Brian Cipenga's late corner, and upset the Indomitable Lions, who are five-time continental champions and hold the African record for the most appearances at the World Cup.
DR Congo's only World Cup appearance came in 1974 and they will contine to battle out for a place at next year's competition against Nigeria in the continental play-off final.
The winner will then progress to a six-team intercontinental qualifier, which will be held in March and will determine the final two nations at next year's World Cup in Canada, Mexico and the United States.
Results in full:
Nigeria 4-1 Gabon
Cameroon 0-1 DR Congo