Tunisia took a major stride towards the Africa Cup of Nations quarter-finals as they beat Niger 2-1 in Libreville.
Issam Jemaa's last-gasp winner was cruel on the Nigeriens, who dominated the Group C encounter at times.
After Youssef Msakni dribbled his way through for a fine goal after just four minutes, William Tonji Ngounou made history when scoring Niger's first Nations Cup goal.
But the debutants' hearts were broken as Jemaa slammed home at the death.
“It hurts because we were in control of the game and it's too bad we should lose in the last minute. We're not going to sleep well tonight, we're really going to regret this game.”
Niger were well-beaten in their group opener by Gabon but against the Tunisians,
who impressed when beating Morocco on Monday
, the Mena showed why they had managed to qualify for their first finals.
After coach Harouna Doula and assistant Rolland Courbis had rung the changes, bringing in five new men, Niger were caught cold in the opening moments.
Msakni, who has proved to be Tunisia's talisman so far, picked up possession some 30 yards from goal and weaved his way unopposed into the penalty box before slotting past a shaky Daouda Kassaly.
Without a goal away from the Nigerien capital Niamey throughout this Nations Cup, the Mena looked set for a long 90 minutes.
Niger's devoted fans will be making an early Nations Cup exit
But just five minutes later, William Tonji Ngounou wrote his name into Niger's record books when he scored the country's first goal at a Nations Cup finals.
Tunisia goalkeeper Aymen Mathlouthi spilled a high bouncing ball under pressure from imposing Niger forward Moussa Maazou, allowing Ngounou to loop a header into an empty net.
Stunned into action, Msakni, 21, threatened again for the 2004 African champions but could not keep two bending efforts on target after he was given yet more room in the box.
In between, Maazou was making a name for himself as the Belgium-based striker terrorised Tunisia's backline with his pace and power.
Continually getting behind the Carthage Eagles defence, the Nigerien should have hit the target when blazing over from eight yards before slipping a side-footed effort a yard wide with Mathlouthi beaten.
“We knew Niger would be well-organised and rigorous on the counter attack. The spirit of my team was there for all to see. Thank God we were able to win - thank God."”
After Issoufou Boubacar hit the post with a snapshot from the edge of the box, Niger seemed to be denied a clear penalty as Tunisia captain Karim Hagui felled the twisting Maazou, 23, in the box, only for Zambian referee Janny Sikazwe to wave play on.
The second half proved a more cautious affair, with Msakni curling a shot wide before Aymen Abdennour hit the post with a 25-yard strike that lacked any real conviction.
Boubacar wasted another promising opening for Niger while at the other end, only some terrific defending denied Tunisia as the North Africans grew ever stronger as the clock ticked down.
Sami Trabelsi's men forced some late pressure as Ammar Jemal went close before Jemaa,
who had not been expected to play in the group stages because of injury
, stole the points.
Quiet since his half-time introduction, the Auxerre striker profited from some slack defending as Niger's back four switched off and he checked inside onto his left foot before drilling home from 10 yards.
It was cruel on Niger but took Tunisia top of the group, with two wins from two, and only co-hosts Gabon can stop them from reaching the last eight when the teams meet in Franceville next Tuesday.
Niger, meanwhile, will hope that Morocco can beat Gabon in Friday's late game to keep alive their slim chances of qualification.