The Swansea striker Wilfried Bony missed from the spot as Algeria edged past Ivory Coast in a dramatic penalty shootout to reach the Africa Cup of Nations semi-finals.
Sofiane Feghouli had fired Les Fennecs into a 20th-minute lead and then saw his teammate Baghdad Bounedjah squander a second-half penalty before Jonathan Kodjia levelled in a tight encounter in Suez.
But the substitute Bony and Serey Die both failed from the spot to send Algeria through 4-3 on penalties for a last-four clash with Nigeria in Cairo on Sunday.
Kodjia failed to make the most of two early chances and Algeria took full advantage when Amir Bensebaini found space on the left with 20 minutes gone and crossed for Feghouli to sweep a shot past Sylvain Gbohouo.
They should have increased their lead after Bounedjah had been felled by Gbohouo 23 seconds after the restart but the striker crashed the spot-kick against the crossbar, and his side was made to pay with 62 minutes gone when Kodjia fired low past Rais Mbohli to level.
Mamadou Bagayoko cleared a Riyad Mahrez shot off the line as Algeria responded but the sides could not be separated in the 90 minutes and, after Gbohouo had beaten away Islam Slimani’s extra-time header, penalties were required.
Wahbi Khazri inspired Tunisia as they powered their way into the semi-finals by ending Madagascar’s unlikely dreams of glory.
Goals from Ferjani Sassi, their captain Youssef Msakni and the substitute Naim Sliti secured a 3-0 quarter-final win in Cairo to set up a showdown with Senegal on Sunday, but it was Khazri who led the way with a fine individual display.
Tunisia enjoyed the better of a keenly contested first half but were unable to make the pressure count. St-Etienne’s Khazri came closest to breaking the deadlock with a curling 32nd-minute free-kick which Melvin Adrien clawed away and the Malagasy keeper had to get down well to turn away Ghaylen Chaaleli’s well-struck effort 10 minutes later.
Khazri thought he had scored seconds after the restart after sliding the ball past Adrien, although a late but correct offside flag ended his celebrations.
However, the opening goal did arrive with 52 minutes gone when Sassi’s shot took a wicked deflection off Thomas Fontaine and wrong-footed the goalkeeper.
It was 2-0 on the hour when Adrien could only parry Khazri’s effort and Msakni followed up to find the bottom corner before the former Sunderland midfielder fed Sliti to complete the scoring in stoppage time.