Algeria had the better of the opening 45 minutes, but they were unable to convert any of the chances that they managed to create.
Two of their best openings fell to 24-year-old Islam Slimani - the first of which he sent over the bar from the edge of the area with 11 minutes on the clock.
He went closer in the 28th minute when he connected with a cross from Valencia midfielder Sofiane Feghouli, but the striker's headed effort rebounded to safety off the crossbar.
Algeria continued to be the more dominant force after the restart and went close 20 minutes from time when Nottingham Forest's Adlene Guedioura sent a 30-yard shot just off target.
Despite spending most of the encounter on the back foot, Hamdi Harbaoui had a good opportunity to win the match for Tunisia with 75 minutes gone, but he missed the target despite being put through with just goalkeeper Rais M'Bolhi to beat.
Just when it looked as though the spoils were going to be shared, Msakni curled the ball beyond M'Bolhi from 20 yards out to win the match for his nation.