Ex- Continent's Best Player of the Year Victor Osimhen was instrumental in Nigeria build a 3-0 lead, before they were forced to defend resolutely for a hard-fought win.
The three-time champions weathered a stunning late rally from their opponents to advance to the last 16 of the Afcon tournament taking place in the host nation.
Jose Peseiro's side appeared to be in complete control in their Group C clash in Fes, enjoying a 3-0 cushion with just a quarter of an hour left courtesy of goals from their attacking trio.
However, Montassar Talbi reduced the deficit with a powerful header from a Hannibal Mejbri set-piece, igniting hopes of a recovery.
The drama intensified when the North Africans were given a spot-kick after a VAR review spotted a handling offense by Bright Osayi-Samuel. The left-back calmly slotted home in the 87th minute to set up a nail-biting finale.
Tunisia came agonizingly close from a last-gasp leveler in stoppage time, with captain Ferjani Sassi directing a chance narrowly wide before Ismael Gharbi sent a bobbling volley past the upright.
The victory means that the Super Eagles, champions of the tournament on three previous occasions, advance to 6 points and are guaranteed first place in their pool with one game still to play.
In the next round, they will face a third-placed side from either the other preliminary groups.
In the other match, Tunisia stay on three points, with Uganda and Tanzania locked on one point after playing out a 1-1 stalemate earlier on Saturday.
The concluding pool matches will see the group leaders stay in the city to play the Cranes on Tuesday, while the Eagles of Carthage return to the capital to face the Taifa Stars.
The Tunisian defender drilled the ball from 12 yards to give Tunisia a glimmer of hope of earning a point.
The Super Eagles, runners-up in the previous tournament, are the second nation after the Pharaohs to qualify for the next phase, but their manager and supporters will certainly be feeling relieved.
What looked like set to be a comfortable last period transformed into a nerve-wracking affair.
The prolific striker had a effort ruled out for offside before breaking the deadlock on the stroke of half-time, precisely placing a glancing effort into the bottom corner from an Ademola Lookman delivery.
The lead was doubled soon in the second half when the Leicester City midfielder rose highest to thump in a header from a set-piece kick.
The number 9 then turned provider his teammate for the third goal, before the defender to steer a header past the Nigerian shot-stopper to begin the fightback.
The key moment came when a looping cross struck the arm of the full-back, with the official awarding a penalty after consulting the pitchside screen.
Despite the defender's confident conversion, the 2004 champions ultimately came up just short of pulling off a stirring recovery.
Tunisia's destiny is still in their control; a point against Tunisia will be sufficient to secure progression, and their coach will be eager to avoid a recurrence of the past early elimination that led to his previous resignation.
A seasoned IT strategist with over 15 years of experience in digital transformation and enterprise software solutions.