Msakni's swift run, dip of the shoulder, cut inside and curling shot provided the moment of inspiration required to break the deadlock at the end of a Group D game dominated by a defensive agenda.
The winger has a reputation for producing pieces of magic in African club competition over the last years but this time left his creativity until right at the end.
His goal handed Tunisia a fortunate three points after they had spent most of the match under pressure from the Algerians, the second ranked side in Africa.
"Neither side deserved to win but it just goes to show that you have keep playing right to the end," Tunisia coach Sami Trabelsi told a news conference.
"This is not a game of logic but football."
Algeria had kept a tight reign throughout the game on their opponents but there were two errors late on.
Tunisia substitute Hamdi Harbaoui might have broken the deadlock 15 minutes earlier on a quick counter attack when Algeria's defence offered a rare opening but the Belgian-based striker missed with just the goalkeeper to beat.
Algeria striker Islam Slimani hit the crossbar with a header just before the half-hour mark in the best chance for his side.
But Algeria can feel hard done by after dominating most of the exchanges, especially the much-anticipated battle in the middle.
"Tunisia had two shots at our goal. I told my players to be careful at the end. It was cruel," said Algeria coach Vahid Halilhodzic.
The former Yugoslavia international felt his side were denied a penalty early in the second half when Sofiane Feghouli went tumbling down under a challenge in the Tunisia box.
The two north African sides were the last of the 16 finalists in South Africa to get their tournament campaigns underway.
Earlier on Tuesday, the Ivory Coast won the opening game in the group also with a late winner when they beat Togo 2-1.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.