Tunisia reached their first Africa Cup of Nations semi-final since 2004 as they ended Madagascar’s fairytale run.
The Eagles of Carthage, who will face Senegal in Sunday’s last-four tie, led through Ferjani Sassi’s deflected shot from the edge of the box.
Youssef Msakni then doubled their lead after Wahbi Khazri’s shot was parried by Melvin Adrien.
Naim Sliti added an injury-time third to cap off a counter-attack as Madagascar sent players forward.
Indian Ocean island sides Madagascar, ranked 108th in the world, were the story of their debut tournament.
They had to start Afcon qualifying in the preliminary round in March 2017, but went on to stun Nigeria in the group stages last month and then DR Congo in the last 16.
Their squad contains players who play in Reunion, the French lower leagues and Thailand. Their head coach Nicolas Dupuis also manages French fourth-tier Fleury.
But their dream came to an end as they were well beaten by a professional Tunisia performance in Cairo.
Tunisia playmaker Khazri was heavily involved in proceedings throughout and had a free-kick tipped over the bar by Adrien. He then thought he had scored their opener, but it was disallowed correctly for offside.
Meanwhile, Algeria reached the semi-finals of the Africa Cup of Nations by beating Ivory Coast 4-3 on penalties following a 1-1 draw after extra time.
Algeria took the lead through ex-West Ham winger Sofiane Feghouli’s side-foot finish before they missed a penalty.
Baghdad Bounedjah, who had been fouled by keeper Sylvain Gbohouo, hit the bar.
Ivory Coast forced extra time after Aston Villa forward Jonathan Kodjia’s low finish but, after no further goals, the tie was decided by penalties.
Algeria, seeking a first Afcon triumph since 1990, will now meet Nigeria in Cairo on Sunday.
Ivory Coast had gone close to scoring when the game was goalless, Rais M’Bolhi pushing Max Gradel’s attempt on to the post.
Crystal Palace forward Wilfried Zaha went into the quarter-final looking to increase his two-goal tally at the tournament.
However, the Ivory Coast player was booked and fortunate to escape a red card after a confrontation with Ramy Bensebaini.
Zaha and Algeria’s Riyad Mahrez had been replaced by the end of the 120 minutes and did not take part in the penalty shootout.
Former Manchester City player Wilfried Bony had already had a penalty saved when team-mate Serey Die hit the post, earning Algeria victory.