Ex- African Footballer of the Year Victor Osimhen helped his team establish a commanding lead, but the Super Eagles were compelled to defend resolutely for a narrow win.
The three-time champions weathered a dramatic late rally from their opponents to progress to the last 16 of the Afcon tournament taking place in Morocco.
The Super Eagles seemed to be in complete control in their pool clash in Fes, enjoying a 3-0 cushion with just 17 minutes remaining thanks to strikes from Victor Osimhen, Wilfred Ndidi and Ademola Lookman.
However, Montassar Talbi pulled one back with a close-range finish from a Hannibal Mejbri free-kick, sparking hopes of a recovery.
The drama escalated when the North Africans were awarded a spot-kick after a video assistant referee review spotted a handball by Bright Osayi-Samuel. The left-back calmly slotted home in the 87th minute to create a nail-biting finale.
The Carthage Eagles were inches away from a last-gasp leveler in added time, with captain Ferjani Sassi directing a opportunity just past the post before Ismael Gharbi sent a bobbling volley past the goal frame.
Clinching Top Spot
The victory ensures that Nigeria, winners of the competition on 3 previous occasions, move to 6 group points and are guaranteed first place in Group C with one game left to play.
In the next round, they will meet a third-placed team from one of the other preliminary groups.
In the other match, the 2004 champions remain on 3 points, with the East African teams locked on a single point after playing out a one-all draw earlier on Saturday.
The concluding group fixtures will see Nigeria remain in the city to play Uganda on the next matchday, while the Eagles of Carthage travel back to Rabat to confront Tanzania.
An Anxious Conclusion
The Tunisian defender drilled the ball from the penalty spot to give his team hope of snatching a draw.
The Super Eagles, finalists in the 2023 tournament, are the next team after Egypt to qualify for the next phase, but their manager and fans will certainly be breathing a sigh of relief.
What seemed set to be a straightforward last period transformed into a nerve-wracking conclusion.
Victor Osimhen had a goal disallowed for offside before breaking the deadlock right before the interval, expertly guiding a header into the far post from an Ademola Lookman cross.
The advantage was doubled soon in the second period when Wilfred Ndidi climbed above everyone to thump in a powerful nod from a Lookman kick.
Osimhen then set up his teammate for the seemingly decisive goal, before Montassar Talbi to steer a header past goalkeeper Stanley Nwabali to begin the comeback.
The key incident came when a looping cross struck the forearm of Bright Osayi-Samuel, with referee Boubou Traore pointing to the spot after consulting the pitchside screen.
Despite the defender's successful penalty, Tunisia in the end came up just short of pulling off a remarkable comeback.
Their fate remains in their control; a draw against Tunisia will be enough to see them through, and their coach will be eager to avoid a recurrence of the past early elimination that led to his previous resignation.