The Manchester City winger was withdrawn in the closing stages of normal time with the score locked at 1-1, but had gone close to winning the game on several occasions.
Instead, the Desert Foxes captain was forced to watch on as former City striker Wilfried Bony and Ivorian skipper Serey Die both missed to send Algeria through to the last four, where they will face Nigeria.
Earlier, Sofiane Feghouli crashed home Ramy Bensebaini’s centre to give the North African nation the lead after 21 minutes, before Baghdad Bounedjah missed a chance to extend their advantage with a penalty he sent crashing against the crossbar.
It proved costly as Aston Villa striker Jonathan Kodjia equalised with a low drive into the bottom corner in the 62nd minute.
Despite a number of chances, that was the extent of the scoring in Suez.
Mahrez’ quality, however, was evident until he was substituted in the 84th minute.
A dancing run and feint opened up an early opportunity, which he dragged wide, but at 1-1 he looked to have won it only for the sliding Mamadou Bagayoko to clear an effort destined for the back of the net.
To extra-time, where, without City’s No.26, chances were few and far between.
Algeria survived a goal mouth scramble and were inches away from scoring a last minute free-kick via Andy Delort, but held their nerve in the shootout to set up Sunday’s semi-final with Nigeria.