Former African Footballer of the Year Victor Osimhen helped Nigeria build a 3-0 advantage, before the Super Eagles were forced to defend resolutely for a hard-fought win.
Nigeria weathered a stunning late rally from Tunisia to progress to the knockout stage of the Afcon tournament taking place in Morocco.
The Super Eagles seemed to be cruising in their pool clash in the Moroccan city, enjoying a 3-0 cushion with only a quarter of an hour remaining courtesy of goals from Victor Osimhen, Wilfred Ndidi and Ademola Lookman.
However, Montassar Talbi reduced the deficit with a close-range finish from a Hannibal Mejbri free-kick, igniting hopes of a recovery.
The drama escalated when Tunisia were awarded a late penalty after a video assistant referee check identified a handling offense by Bright Osayi-Samuel. The left-back converted in the dying stages to set up a nail-biting conclusion.
Tunisia were inches away from a last-gasp leveler in stoppage time, with captain Ferjani Sassi heading a chance just past the post before a substitute guided a half-volley past the goal frame.
The victory ensures that the Super Eagles, winners of the competition on 3 past instances, move to six group points and are assured first place in Group C with a match left to be contested.
For the round of 16, they will meet a best third-place team from one of the other preliminary groups.
Meanwhile, Tunisia stay on 3 points, with the East African teams locked on one point after registering a one-all stalemate in the day's other fixture.
The concluding group matches will see the group leaders remain in the city to take on the Cranes on Tuesday, while the Eagles of Carthage return to the capital to confront the Taifa Stars.
Ali Abdi drilled home from the penalty spot to offer Tunisia hope of snatching a draw.
Nigeria, runners-up in the previous edition, are the next team after the Pharaohs to reach the next phase, but coach Eric Chelle and fans will undoubtedly be feeling relieved.
What seemed set to be a comfortable final quarter morphed into a tense affair.
Victor Osimhen had a goal ruled out for an infringement before breaking the deadlock on the stroke of half-time, precisely placing a glancing effort into the bottom corner from an Atalanta winger cross.
The advantage was doubled soon in the second half when the Leicester City midfielder climbed above everyone to thump in a powerful nod from a Lookman kick.
Osimhen then set up his teammate for the third goal, before Montassar Talbi to steer a powerful header past the Nigerian shot-stopper to initiate the comeback.
The pivotal moment came when a high ball struck the forearm of the full-back, with referee Boubou Traore pointing to the spot after consulting the pitchside screen.
Despite the defender's successful penalty, Tunisia ultimately fell short of completing a remarkable comeback.
Tunisia's destiny remains in their own hands; a draw against Tanzania will be enough to see them through, and manager Sami Trabelsi will be keen to avoid a repeat of the past early elimination that led to his departure.