Former Continent's Best Player of the Year Victor Osimhen helped his team build a 3-0 advantage, but they were compelled to hold on for a narrow win.
The three-time champions weathered a stunning comeback attempt from their opponents to progress to the last 16 of the Afcon tournament being held in the host nation.
The Super Eagles appeared to be in complete control in their Group C clash in the Moroccan city, holding a 3-0 lead with just a quarter of an hour remaining courtesy of goals from their attacking trio.
Yet, Montassar Talbi reduced the deficit with a powerful header from a Hannibal Mejbri set-piece, sparking hopes of a recovery.
The drama intensified when Tunisia were awarded a late penalty after a video assistant referee review spotted a handball by the Nigerian defender. Ali Abdi converted in the dying stages to create a frantic conclusion.
The Carthage Eagles came agonizingly close from a stunning leveler in stoppage time, with their skipper heading a chance just past the post before Ismael Gharbi sent a half-volley wide of the upright.
This result ensures that the Super Eagles, winners of the tournament on three past instances, advance to 6 group points and are assured top spot in their pool with one game left to be contested.
For the round of 16, they will face a best third-place side from either the other preliminary groups.
In the other match, the 2004 champions remain on 3 group points, with Uganda and Tanzania locked on a single point each after playing out a 1-1 stalemate earlier on Saturday.
The final group matches will see the group leaders stay in the city to play the Cranes on the next matchday, while the Eagles of Carthage return to Rabat to face Tanzania.
The Tunisian defender smashed home from 12 yards to give Tunisia hope of snatching a point.
Nigeria, finalists in the 2023 tournament, are the second team after the Pharaohs to qualify for the knockout stage, but their manager and supporters will certainly be feeling relieved.
What seemed set to be a comfortable final quarter morphed into a tense conclusion.
Victor Osimhen had a effort ruled out for offside before opening the scoring on the stroke of half-time, expertly guiding a header into the far post from an Atalanta winger cross.
The advantage was extended soon in the second period when the Leicester City midfielder climbed above everyone to thump in a powerful nod from a set-piece corner.
Osimhen then turned provider Lookman for the third goal, only for Montassar Talbi to steer a header past goalkeeper Stanley Nwabali to begin the comeback.
The pivotal incident arrived when a looping cross hit the forearm of Bright Osayi-Samuel, with the official pointing to the spot after reviewing the pitchside screen.
Despite Ali Abdi's confident conversion, the 2004 champions in the end came up just short of pulling off a remarkable comeback.
Their fate remains in their control; a point against Tanzania will be enough to see them through, and their coach will be keen to prevent a recurrence of the past group-stage exit that resulted in his previous resignation.
Elara Vance is a seasoned business analyst with over a decade of experience covering international markets and industrial transformations.