Algeria were the better side over 90 minutes, but could not make much of their possession, and were undone in the end by a moment of class from Msakni.
Tunisia coach Sami Trabelsi had to make a first substitution after just 16 minues, when Issam Jemaa was forced off after a clash with Essaid Belkalem. He was replaced by Hamdi Harbaoui.
Algeria hit the woodwork on the half-hour mark, when Sofiane Feghouli sent in a great cross that was met by Islam Slimani, who watched his header bounce off the crossbar.
The Fennec Foxes followed that up with a couple more chances as they started to probe the Tunisian defence. First, Mejdi Traoui cleared Djamel Mesbah's cross out of danger with an acrobatic header. A few minutes later the ball fell to Foued Kadir in the box, but the midfielder kicked and missed and it went out for a goal-kick.
Tunisia had their first real chance of the match just before half-time, when Hamdi Harbaoui showed his pace before unleashing a shot – straight at Rais Mbolhi.
Djamel Mesbah had a free-kick from 30 metres for Algeria at the start of the second half, but his delivery was woeful – low and wide. A few minutes later he went on a purposeful run, and his shot at the end of it was closer, but still wide of the mark.
Half an hour into the second half Algeria’s Adlene Guedioura let loose with a thunderous shot from 25 metres out that dipped behind the goalkeeper’s head, but flew inches over the bar.
Hamdi Harbaoui should have made it 1-0 to Tunisa a few minutes later, when he received a pin-point pass from Oussama Darragi, but the striker hit just wide from close range.
Then, deep into injury time, Youssef Msakni unleashed a rocket of a ball, curling it in from outside the box and into the top corner.
The ‘Little Mozart’s’ topless goal celebrations earned him a yellow card but the Carthage Eagles came away with an invaluable three points in the 2013 Afcon 'group of death'.