Former African Footballer of the Year Victor Osimhen was instrumental in his team establish a 3-0 lead, but they were forced to defend resolutely for a hard-fought victory.
Nigeria weathered a dramatic comeback attempt from Tunisia to progress to the last 16 of the Afcon tournament taking place in the host nation.
Jose Peseiro's side seemed to be in complete control in their pool clash in the Moroccan city, enjoying a three-goal cushion with only 17 minutes remaining courtesy of strikes from Victor Osimhen, Wilfred Ndidi and Ademola Lookman.
However, a Tunisian defender reduced the deficit with a powerful header from a Manchester United midfielder free-kick, sparking hopes of a recovery.
The drama escalated when Tunisia were given a late penalty after a VAR check identified a handling offense by the Nigerian defender. The left-back calmly slotted home in the dying stages to set up a frantic conclusion.
Tunisia were inches away from a stunning leveler in stoppage time, with their skipper heading a chance narrowly wide before Ismael Gharbi guided a bobbling volley wide of the upright.
Clinching Top Spot
This result ensures that Nigeria, winners of the competition on 3 past instances, move to 6 points and are assured first place in Group C with a match still to play.
For the round of 16, they will meet a third-placed side from one of the other preliminary groups.
In the other match, the 2004 champions remain on 3 group points, with the East African teams locked on a single point each after playing out a one-all stalemate in the day's other fixture.
The final group fixtures will see the group leaders remain in the city to play Uganda on Tuesday, while Tunisia travel back to Rabat to face Tanzania.
A Nervy Finish
Ali Abdi drilled the ball from 12 yards to offer Tunisia a glimmer of hope of snatching a draw.
Nigeria, runners-up in the 2023 tournament, are the next nation after the Pharaohs to reach the knockout stage, but coach Eric Chelle and supporters will undoubtedly be breathing a sigh of relief.
What looked like set to be a straightforward last period transformed into a nerve-wracking affair.
The prolific striker had a effort ruled out for an infringement before opening the scoring on the stroke of the interval, expertly guiding a header into the far post from an Atalanta winger delivery.
The lead was extended early in the second half when Wilfred Ndidi rose highest to thump in a header from a set-piece corner.
Osimhen then turned provider Lookman for the third goal, before the defender to direct a header past the Nigerian shot-stopper to initiate the fightback.
The pivotal moment came when a high ball hit the arm of the full-back, with the official awarding a penalty after reviewing the pitchside screen.
Despite the defender's confident conversion, the 2004 champions in the end fell short of completing a stirring recovery.
Their fate is still in their own hands; a point against Tunisia will be sufficient to secure progression, and manager Sami Trabelsi will be keen to avoid a recurrence of the 2013 early elimination that led to his previous resignation.