That set up a semifinal for Tunisia against Senegal and finally sent Madagascar, which was playing in its first major tournament, home. Ferjani Sassi claimed the opener in the 52nd minute, helped by a big deflection off the backside of Madagascar defender Thomas Fontaine. Tunisia captain Youssef Msakni pounced on a rebound to make it 2-0.
Naim Sliti scored a third on a Tunisian breakaway deep in injury time as the Madagascans piled forward in search of something to give them hope. Tunisia now faces Sadio Mane and the tournament favorite in the last four. Algeria and Nigeria play in the other semi. Both matches are on Sunday.
The Algerians blew a 1-0 lead and a penalty in regulation time before scraping past Ivory Coast in a dramatic shootout in their quarterfinal. Tunisia deserved its win at Al Salam Stadium on the outskirts of Cairo, where Madagascar was hoping to continue a dream debut by making the last four.
It didn't happen, but the African Cup first-timer it lit up the early parts of the tournament by stunning three-time champion Nigeria 2-0 in the group stage and getting past Congo, another former champion, in the last 16.
It was a surprise that Madagascar — ranked 108th by FIFA, just behind the Faroe Islands — even qualified for the tournament in Egypt. It ended up topping its group above Nigeria and making the last eight, and it also brought the Barea celebration to the world.
The team takes its nickname from a breed of cattle found in Madagascar, and the players celebrated each of their goals at the African Cup by putting their hands on either side of their heads and pointing their fingers up in the air like horns.
They had their country's president and the African soccer body president, who is also from Madagascar, at Al Salam Stadium to cheer them on. In Suez, the tense shootout between Algeria and Ivory Coast, which Algeria won 4-3, capped a pulsating quarterfinal that went end to end.
Wilfried Bony had his penalty saved in the shootout by Rais Mbolhi to give Algeria the advantage. But Youcef Belaili hit the post with a spot kick that would have won it for the Algerians. Straight after, Ivory Coast captain Serey Die had to score to send the shootout to sudden death, and he cannoned his penalty off the same post to finally seal victory for the Algerians.
Die fell back flat on his back and put his hands over his face after his miss as the Algerians sprinted to the end of the field to celebrate with Mbolhi. Algeria led in regulation after Sofiane Feghouli's goal in the 20th minute. Striker Baghdad Bounedjah missed a penalty for Algeria soon after halftime, and Jonathan Kodjia equalized for Ivory Coast.
Bounedjah won the penalty himself when he was taken out by Ivory Coast goalkeeper Sylvain Gbohouo. With the chance to give Algeria a 2-0 lead, he hit his penalty high down the middle, and it clipped the crossbar and went over.
Ivory Coast took advantage. Wilfried Zaha made a surging run and found Kodjia on the right. He cut in and put his shot in the bottom corner. Bounedjah was substituted in the second half and spent the rest of the game in tears on the bench, fearing his miss had cost Algeria a place in the last four.
It didn't, and Algeria still has the chance to win its second African title and first since 1990.
More AP soccer: https://apnews.com/apf-Soccer and https://twitter.com/AP_Sports