Substitute Issam Jemaa struck a last-gasp winner to help Tunisia move a step closer to the Africa Cup of Nations quarter-finals after edging out unlucky Niger in a hugely entertaining encounter in Libreville.
Tunisia took a fourth-minute lead through the impressive Youssef Msakni but Niger equalised four minutes later in controversial fashion when William N'Gounou netted following a possible handball from his team-mate Ouwo Moussa Maazou.
Both teams created a host of chances after that, including each hitting the woodwork, but it was Tunisia who claimed the points when Jemaa netted in the 90th minute.
The victory leaves Tunisia top of Group C with two wins from two, while Niger prop up the pool having also lost their first match to Gabon.
Niger's towering striker Maazou was rarely far from the action during the first half and, aside from his controversial role in his side's goal, he also missed three one-on-one opportunities.
The first came inside the opening two minutes when he was let down by a heavy first touch and Tunisia goalkeeper Aymen Mathlouthi was able to gather.
Two minutes after that, Niger found themselves trailing as Msakni netted a fine solo goal.
Picking the ball up 40 yards from goal, the 21-year-old showed good footwork to twice evade challenges as he worked his way into the area before coolly side-footing past Kassaly Daouda.
Zouheir Dhaouadi went close to doubling Tunisia's lead soon after but, just as it seemed like the north Africa side were taking control, Niger drew level in contentious circumstances.
Maazou stuck up a hand as he challenged Mathlouthi for a bouncing ball in the Tunisia area and, although it was not clear whether he touched the ball or not, the action appeared to distract
Mathlouthi as he dropped the ball, allowing N'Gounou to head it into an empty net.
The Tunisia players were furious but the goal stood and Niger were back on level terms.
That is the way the score stayed until half-time, although both countries had chances to add to the scoreline.
The skilful Msakni curled over for Tunisia before Maazou missed his second one-on-one as he blazed high and wide going for the near top corner after latching onto a superb through-ball.
Maazou's third clear opportunity arrived in the 30th minute when the 23-year-old showed blistering pace to burst through the Tunisia defence, but he was again unable to finish with only Mathlouthi to beat as he side-footed wide of the far post.
Niger were giving the Tunisia defence a torrid time and in the 34th minute Boubacar Issoufou struck the outside of the post with a low shot from the edge of the area, while on the stroke of half-time Maazou felt he should have been awarded a penalty following a challenge by Karim Haggui.
The second half continued to produce plenty of attacking football and Msakni curled another good opening wide before Tunisia struck the post themselves through Aymen Abdennour in the 64th minute.
Both sides pushed for a late winner, but after Issoufou and Maazou had failed to make the most of their chances for Niger, it was Tunisia who took the points thanks to Jemaa, who cut inside Chikoto Mohamed before drilling a shot past Daouda.
There was still time after that for Tunisia to hit the underside of the bar through Oussama Darragi, but they had already done enough to claim the win.