Ex- Continent's Best Player of the Year the Napoli star helped his team establish a commanding lead, but they were compelled to defend resolutely for a narrow win.
The three-time champions survived a stunning late rally from their opponents to advance to the last 16 of the Afcon tournament being held in the host nation.
The Super Eagles seemed to be cruising in their Group C clash in the Moroccan city, holding a 3-0 cushion with only 17 minutes remaining courtesy of goals from Victor Osimhen, Wilfred Ndidi and Ademola Lookman.
However, a Tunisian defender reduced the deficit with a close-range finish from a Manchester United midfielder free-kick, sparking hopes of a recovery.
The tension escalated when the North Africans were awarded a spot-kick after a video assistant referee review spotted a handling offense by the Nigerian defender. The left-back converted in the dying stages to create a frantic finale.
Tunisia were inches away from a stunning leveler in added time, with their skipper heading a chance just past the post before Ismael Gharbi guided a half-volley past the goal frame.
Clinching First Place
This result ensures that the Super Eagles, champions of the tournament on 3 previous occasions, move to 6 points and are guaranteed top spot in Group C with one game left to be contested.
In the next round, they will meet a best third-place side from either Group A, B or F.
In the other match, Tunisia stay on three points, with the East African teams locked on a single point each after playing out a one-all draw in the day's other fixture.
The final pool matches will see the group leaders stay in Fes to take on Uganda on the next matchday, while Tunisia return to Rabat to face Tanzania.
An Anxious Finish
The Tunisian defender smashed the ball from 12 yards to give his team hope of earning a point.
Nigeria, runners-up in the previous 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 seemed set to be a comfortable final quarter transformed into a nerve-wracking affair.
The prolific striker had a effort ruled out for offside before breaking the deadlock on the stroke of the interval, expertly guiding a header into the far post from an Ademola Lookman delivery.
The lead was extended soon in the second period when Wilfred Ndidi rose highest to power home a header from a Lookman kick.
The number 9 then turned provider Lookman for the third goal, before Montassar Talbi to direct a powerful header past goalkeeper Stanley Nwabali to initiate the comeback.
The pivotal moment arrived when a high ball hit the forearm of Bright Osayi-Samuel, with referee Boubou Traore pointing to the spot after consulting the pitchside screen.
Although Ali Abdi's confident conversion, the 2004 champions in the end came up just short of completing a stirring recovery.
Their fate remains in their control; a point against Tanzania will be sufficient to secure progression, and their coach will be keen to prevent a recurrence of the past group-stage exit that resulted in his previous resignation.