Former Continent's Best Player of the Year Victor Osimhen helped Nigeria establish a 3-0 advantage, before the Super Eagles were compelled to defend resolutely for a narrow win.
Nigeria survived a dramatic late rally from their opponents to advance to the knockout stage of the Afcon tournament taking place in the host nation.
Jose Peseiro's side seemed to be cruising in their Group C encounter in the Moroccan city, holding a 3-0 cushion with only a quarter of an hour left courtesy of strikes from their attacking trio.
However, Montassar Talbi reduced the deficit with a close-range finish from a Hannibal Mejbri set-piece, sparking hopes of a turnaround.
The drama intensified when Tunisia were awarded a spot-kick after a VAR check spotted a handball by Bright Osayi-Samuel. Ali Abdi converted in the dying stages to create a nail-biting conclusion.
Tunisia came agonizingly close from a last-gasp leveler in stoppage time, with captain Ferjani Sassi directing a opportunity narrowly wide before a substitute guided a half-volley wide of the upright.
Securing Top Spot
This result means that Nigeria, champions of the tournament on 3 previous occasions, move to 6 points and are guaranteed top spot in Group C with one game still to be contested.
In the next round, they will meet a third-placed team from either the other preliminary groups.
Meanwhile, Tunisia stay on 3 group points, with the East African teams locked on one point each after playing out a 1-1 stalemate in the day's other fixture.
The concluding pool fixtures will see the group leaders stay in the city to play the Cranes on Tuesday, while Tunisia travel back to Rabat to confront the Taifa Stars.
A Nervy Conclusion
The Tunisian defender drilled the ball from 12 yards to give Tunisia a glimmer of hope of earning a point.
Nigeria, finalists in the previous tournament, are the second nation after the Pharaohs to reach the knockout stage, but their manager and supporters will certainly be feeling relieved.
What seemed set to be a comfortable final quarter transformed into a nerve-wracking conclusion.
Victor Osimhen had a effort ruled out for an infringement before breaking the deadlock right before half-time, precisely placing a glancing effort into the far post from an Ademola Lookman delivery.
The advantage was extended soon in the second half when Wilfred Ndidi climbed above everyone to power home a header from a set-piece corner.
Osimhen then turned provider Lookman for the third goal, before Montassar Talbi to steer a powerful header past the Nigerian shot-stopper to begin the comeback.
The key incident came when a looping cross struck the arm of Bright Osayi-Samuel, with the official awarding a penalty after reviewing the pitchside screen.
Despite the defender's successful penalty, Tunisia ultimately came up just short of completing a remarkable comeback.
Tunisia's destiny remains in their control; a point against Tanzania will be enough to secure progression, and their coach will be keen to prevent a repeat of the 2013 early elimination that led to his previous resignation.