Msakni struck on 47 minutes and Nigerian hopes of levelling were dealt a major blow midway through the second half when Alex Iwobi was red-carded.
Nigeria started as favourites to reach the quarter-finals having won all three group matches in the northwestern city, with record seven-time champions Egypt among their victims.
Tunisia, making a record 15th consecutive Cup of Nations appearance from 1994, fell to Mali and minnows Gambia in the first round and squeezed into the knockout phase among the four best third-placed teams.
While Nigeria were able to choose 12 substitutes, Tunisia could manage only eight due to a coronavirus outbreak in the camp.
Also missing due to Covid-19 was Tunisia coach Mondher Kebaier, who was isolating in coastal city Limbe at the other end of the central African country.
Apart from being the more impressive in the group phase, the Nigerian Super Eagles also boasted an unbeaten record in five previous meetings with the Carthage Eagles, winning three and drawing two.
A lacklustre opening half produced only one shot on target, from Tunisia, as Nigeria were unable to recapture the first-round form that made them the only team among the 24 to boast a 100 percent record.
In a tournament full of surprises, another one arrived just after half-time when Qatar-based Msakni put the one-time Cup of Nations champions ahead.
Msakni, playing in his seventh Cup of Nations tournament, dribbled across the edge of the box before unleashing a curling shot that entered the net off the left arm of goalkeeper Maduka Okoye.
As Nigeria battled to break down a well-organised Tunisian defence, they suffered another blow midway through the second half when Iwobi had a yellow card changed to red after a VAR check.
Iwobi, an Everton winger and one of many Premier League players in Cameroon, had just come off the bench when he stamped on the ankle of Msakni.
Another substitute, Naim Sliti, almost doubled the Tunisian lead with 15 minutes remaining when he fired a shot toward the corner of the net only to be thwarted by a superb two-hand save from Okoye.
Nigeria had a chance to level as time ticked away, but Moses Simon sent a free-kick from just outside the box over the crossbar.