Wilfried Bony missed from the spot as Algeria edged past the Ivory Coast in a dramatic penalty shoot-out to reach the Africa Cup of Nations semi-finals.
Sofiane Feghouli had fired Les Fennecs into a 20th-minute lead and then saw team-mate Baghdad Bounedjah squander a second-half penalty before Jonathan Kodjia levelled in a tight encounter in Suez.
But substitute Bony and skipper Serey Die both failed from the spot to send Algeria through 4-3 on penalties to set up 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 keeper Sylvain Gbohouo.
They should have increased their lead after Bounedjah had been felled by Gbohouo just 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 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 substitute Islam Slimani’s extra-time header, penalties were required.
Stay updated with the latest news, gossip and football stories by following us @Football_P