Interestingly, Tunisia notched their first win of the tournament in the process.
Madagascar, a country with little football tradition and who had not been expected to progress beyond the group stage on their first appearance at the finals, held out until the second half.
They were first undone by Ferjani Sassi’s deflected shot.
Youssef Msakni added a second on the hour for the Carthage Eagles, ranked 25th in the world against Madagascar’s 107th.
And substitute Naim Sliti finished it off on the break in stoppage time to earn them a semi-final against Senegal on Sunday.
Tunisia had drawn their previous four matches at the tournament, beating Ghana on penalties in the last 16.
“We’re the first to beat Madagascar. We had to do it to qualify and that proves the quality of this team,” said Tunisia coach Alain Giresse.
“When you get to this stage, for which Tunisia was waiting for several years… We want to go as far as possible. We haven’t stolen it from anyone, we deserve it.”
Madagascar coach Nicolas Dupuis, whose contract was set to expire at the end of the competition, admitted Tunisia were simply too strong.
“I’m very proud of what the players have done since the start of the tournament. I tip my hat to them,” said Dupuis.
“Today the step was too high. As for my future, it doesn’t matter much. I’m someone loyal and my priority is Madagascar.”