Ex- African Footballer of the Year Victor Osimhen helped Nigeria establish a 3-0 lead, before they were forced to hold on for a hard-fought victory.
Nigeria weathered a dramatic comeback attempt from Tunisia to advance to the knockout stage of the Afcon tournament being held in the host nation.
The Super Eagles appeared to be cruising in their pool clash in Fes, holding a 3-0 cushion with only a quarter of an hour left courtesy of goals from Victor Osimhen, Wilfred Ndidi and Ademola Lookman.
However, Montassar Talbi reduced the deficit with a powerful header from a Manchester United midfielder free-kick, sparking hopes of a turnaround.
The tension intensified when the North Africans were awarded a late penalty after a video assistant referee check identified a handball by Bright Osayi-Samuel. Ali Abdi calmly slotted home in the 87th minute to create a frantic conclusion.
The Carthage Eagles came agonizingly close from a stunning leveler in added time, with captain Ferjani Sassi directing a chance just past the post before a substitute guided a bobbling volley past the goal frame.
Securing First Place
The victory ensures that the Super Eagles, champions of the tournament on 3 previous occasions, advance to six group points and are assured first place in their pool with a match left to play.
In the next round, they will face a best third-place team from one of the other preliminary groups.
Meanwhile, the 2004 champions stay on 3 group points, with the East African teams tied on a single point each after registering a 1-1 stalemate earlier on Saturday.
The final pool matches will see Nigeria stay in Fes to take on the Cranes on Tuesday, while the Eagles of Carthage travel back to the capital to face the Taifa Stars.
A Nervy Finish
The Tunisian defender smashed the ball from the penalty spot to give Tunisia hope of earning a draw.
Nigeria, runners-up in the previous edition, become the second nation after Egypt to qualify for the knockout stage, but coach Eric Chelle and fans will certainly be breathing a sigh of relief.
What seemed set to be a comfortable last period transformed into a tense conclusion.
Victor Osimhen had a effort ruled out for an infringement before opening the scoring right before half-time, expertly guiding a header into the far post from an Ademola Lookman delivery.
The advantage was doubled early in the second period when Wilfred Ndidi rose highest to thump in a header from a set-piece kick.
Osimhen then turned provider his teammate for the seemingly decisive goal, only for the defender to direct a powerful header past goalkeeper Stanley Nwabali to initiate the fightback.
The key moment arrived when a looping cross struck the forearm of the full-back, with referee Boubou Traore awarding a penalty after consulting the VAR monitor.
Although Ali Abdi's successful penalty, Tunisia in the end fell short of pulling off a stirring recovery.
Their fate is still in their control; a draw against Tunisia will be enough to see them through, and their coach will be keen to prevent a repeat of the past early elimination that led to his departure.