Aymen Mahious scored his third winning goal of the African Nations Championship to take hosts Algeria into the semi-finals with a last-gasp 1-0 win over the Ivory Coast on Friday.
The referee initially ignored added-time appeals for a foul, but changed his decision to a penalty after reviewing the incident on the VAR pitchside monitor.
Mahious, scorer of the only goals in group victories over Libya and Ethiopia, calmly slotted the 96th-minute spot-kick into the corner of the net while goalkeeper Ayayi Folly barely moved.
A solitary goal always seemed likely to settle a close, physical encounter before a near-capacity crowd at the 40,000-seat Stade Nelson Mandela in Algiers.
Clear-cut scoring chances were scarce with Mahious the focal point of many Algerian attacks in the second half of the first quarter-final.
Both sides were reduced to 10 men in an opening half that kept the impressive Mauritanian referee on his toes.
Algeria goalkeeper Alexis Guendouz was first to be dismissed when he charged out of his penalty area on 20 minutes and handled the ball after fouling Sankara Karamoko.
The numerical advantage enjoyed by the Ivorians lasted only 14 minutes, however, before Kouassi Attohoula was red-carded following a tackle that left Mokhtar Belkhiter wincing with pain.
After four matches in the capital, Algeria will travel west to Oran, the second largest city, for a semi-final showdown with Ghana or Niger on Tuesday.
Appearing for only the second time in a tournament restricted to footballers playing in their country of birth, Algeria hope to improve on a fourth-place finish in Sudan 12 years ago.
Hosts have traditionally struggled in the CHAN with 2018 winners Morocco the only one of six champions who maximised home advantage.
In Annaba, Senegal, involved in the finals for the first time since 2011, edged west African neighbours Mauritania 1-0 in another quarter-final decided by a penalty.
A shirt-pulling incident offered an opportunity for the Senegalese to go ahead on 34 minutes and they took it with teenager Lamine Camara firing past goalkeeper Namori Diaw.
On Saturday, first-time quarter-finalists Madagascar and Mozambique clash in Constantine followed by two-time runners-up Ghana against Niger in Oran.