A mistake by goalkeeper Mouez Hassen in the 100th minute saw the ball bounce off the head of defender Dylan Bronn and trickle into the net.
Hassen came racing towards the penalty spot to try to cut out a cross from the right flank but completely missed the ball, which then hit the unfortunate Bronn.
Ferjani Sassi missed a penalty for Tunisia and Henri Saivet did likewise for Senegal but that was not the end of the drama.
Tunisia felt aggrieved as they were awarded another spot-kick late on after Salif Sane headed the ball against Idrissa Gueye's arm, only for that decision to be controversially overturned following a VAR check.
Senegal survived and are through to only their second Africa Cup of Nations final, having lost in 2002.