Former African Footballer of the Year Victor Osimhen was instrumental in Nigeria establish a 3-0 lead, but the Super Eagles were forced to hold on for a hard-fought win.
Nigeria weathered a dramatic late rally from their opponents to advance to the last 16 of the 2025 Africa Cup of Nations taking place in the host nation.
Jose Peseiro's side appeared to be in complete control in their pool clash in the Moroccan city, holding a 3-0 lead with just 17 minutes remaining courtesy of goals from Victor Osimhen, Wilfred Ndidi and Ademola Lookman.
However, a Tunisian defender pulled one back with a powerful header from a Manchester United midfielder set-piece, igniting hopes of a turnaround.
The drama escalated when the North Africans were awarded a spot-kick after a VAR review spotted a handball by the Nigerian defender. The left-back converted in the dying stages to set up a nail-biting finale.
Tunisia came agonizingly close from a last-gasp leveler in stoppage time, with their skipper heading a chance just past the post before a substitute guided a half-volley past the upright.
This result ensures that Nigeria, champions of the tournament on three past instances, advance to six group points and are guaranteed top spot in their pool with one game still to play.
For the round of 16, they will face a third-placed team from either the other preliminary groups.
In the other match, Tunisia remain on three group points, with the East African teams tied on a single point after playing out a 1-1 stalemate in the day's other fixture.
The concluding group matches will see Nigeria remain in the city to take on the Cranes on the next matchday, while Tunisia return to Rabat to face the Taifa Stars.
The Tunisian defender smashed home from the penalty spot to offer Tunisia a glimmer of hope of snatching a point.
Nigeria, finalists in the 2023 edition, are the next nation after Egypt to reach the knockout stage, but their manager and fans will undoubtedly be feeling relieved.
What looked like set to be a comfortable final quarter transformed into a tense conclusion.
Victor Osimhen had a goal ruled out for an infringement before breaking the deadlock right before half-time, expertly guiding a header into the bottom corner from an Ademola Lookman delivery.
The lead was doubled early in the second half when the Leicester City midfielder rose highest to thump in a header from a Lookman corner.
Osimhen then set up his teammate for the third goal, only for the defender to direct a powerful header past goalkeeper Stanley Nwabali to begin the fightback.
The key incident came when a looping cross struck the forearm of the full-back, with referee Boubou Traore pointing to the spot after reviewing the VAR monitor.
Despite Ali Abdi's successful penalty, Tunisia in the end fell short of pulling off a stirring recovery.
Their fate remains in their own hands; a point against Tunisia will be enough to see them through, and manager Sami Trabelsi will be keen to avoid a repeat of the past early elimination that resulted in his departure.