Ex- African Footballer of the Year Victor Osimhen helped Nigeria build a 3-0 advantage, but they were compelled to defend resolutely for a narrow win.
The three-time champions survived a dramatic late rally from Tunisia to advance to the knockout stage of the 2025 Africa Cup of Nations being held in the host nation.
Jose Peseiro's side seemed to be cruising in their Group C clash in Fes, holding a 3-0 lead with just a quarter of an hour remaining courtesy of strikes from their attacking trio.
Yet, Montassar Talbi reduced the deficit with a powerful header from a Hannibal Mejbri set-piece, igniting hopes of a turnaround.
The tension escalated when the North Africans were awarded a spot-kick after a video assistant referee review identified a handball by Bright Osayi-Samuel. Ali Abdi converted in the dying stages to create a nail-biting conclusion.
The Carthage Eagles were inches away from a stunning equalizer in added time, with their skipper heading a opportunity just past the post before Ismael Gharbi guided a bobbling volley past the goal frame.
This result ensures that Nigeria, winners of the competition on three previous occasions, move to six points and are assured top spot in their pool with a match still to be contested.
In the next round, they will meet a third-placed side from one of the other preliminary groups.
In the other match, Tunisia remain on three points, with Uganda and Tanzania locked on a single point each after registering a one-all draw in the day's other fixture.
The final pool fixtures will see Nigeria remain in the city to take on Uganda on Tuesday, while the Eagles of Carthage travel back to Rabat to confront Tanzania.
Ali Abdi smashed the ball from the penalty spot to offer Tunisia hope of earning a point.
Nigeria, runners-up in the previous tournament, become the second nation after Egypt to reach the knockout stage, but their manager and supporters will undoubtedly be feeling relieved.
What looked like set to be a comfortable last period morphed into a nerve-wracking affair.
Victor Osimhen had a effort ruled out for an infringement before breaking the deadlock on the stroke of the interval, precisely placing a header into the far post from an Ademola Lookman delivery.
The lead was doubled soon in the second period when the Leicester City midfielder rose highest to power home a powerful nod from a Lookman kick.
The number 9 then turned provider Lookman for the third goal, only for the defender to direct a header past goalkeeper Stanley Nwabali to begin the comeback.
The key moment arrived when a high ball struck the arm of the full-back, with the official pointing to the spot after consulting the pitchside screen.
Despite the defender's confident conversion, the 2004 champions in the end fell short of completing a remarkable comeback.
Their fate is still in their control; a point against Tanzania will be sufficient to secure progression, and their coach will be keen to avoid a repeat of the 2013 early elimination that led to his previous resignation.
A seasoned gaming analyst with over a decade of experience in online casino reviews and strategy development.