Ex- Continent's Best Player of the Year Victor Osimhen was instrumental in his team build a 3-0 advantage, but the Super Eagles were compelled to hold on for a narrow victory.
Nigeria weathered a stunning comeback attempt from their opponents to advance to the last 16 of the Afcon tournament being held in the host nation.
The Super Eagles appeared to be in complete control in their Group C clash in the Moroccan city, enjoying a 3-0 cushion with just a quarter of an hour left thanks to goals from their attacking trio.
Yet, Montassar Talbi reduced the deficit with a powerful header from a Hannibal Mejbri free-kick, igniting hopes of a turnaround.
The drama intensified when the North Africans were awarded a late penalty after a video assistant referee check identified a handball by Bright Osayi-Samuel. Ali Abdi calmly slotted home in the dying stages to create a frantic conclusion.
Tunisia came agonizingly close from a last-gasp leveler in added time, with captain Ferjani Sassi directing a opportunity narrowly wide before Ismael Gharbi guided a half-volley past the goal frame.
The victory ensures that Nigeria, champions of the tournament on 3 past instances, move to six group points and are assured first place in their pool with a match left to play.
In the next round, they will meet a best third-place team from one of Group A, B or F.
Meanwhile, the 2004 champions remain on three group points, with Uganda and Tanzania tied on a single point each after registering a 1-1 draw earlier on Saturday.
The concluding pool matches will see Nigeria stay in Fes to take on the Cranes on the next matchday, while Tunisia travel back to the capital to confront the Taifa Stars.
The Tunisian defender smashed the ball from 12 yards to give his team hope of snatching a draw.
The Super Eagles, finalists in the 2023 tournament, become the next nation after Egypt to reach the knockout stage, but coach Eric Chelle and fans 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 goal ruled out for offside before breaking the deadlock right before half-time, precisely placing a glancing effort into the far post from an Ademola Lookman delivery.
The lead was extended soon in the second half when Wilfred Ndidi climbed above everyone to thump in a header from a Lookman corner.
Osimhen then turned provider Lookman for the seemingly decisive goal, before Montassar Talbi to direct a header past goalkeeper Stanley Nwabali to initiate the comeback.
The key moment arrived when a looping cross struck the arm of the full-back, with the official pointing to the spot after reviewing the VAR monitor.
Despite Ali Abdi's confident conversion, the 2004 champions in the end fell short of pulling off a stirring comeback.
Their fate remains in their control; a point against Tanzania will be enough to see them through, and their coach will be keen to prevent a recurrence of the past group-stage exit that led to his departure.
A seasoned gambling analyst with over a decade of experience in online casino reviews and player advocacy.