Winger Riyad Mahrez scored a stunning stoppage-time free-kick to secure Algeria a dramatic 2-1 victory over three-time champions Nigeria on Sunday, teeing up a rematch with Senegal in the Africa Cup of Nations final.
Algeria took the lead from a first-half own goal by William Troost-Ekong before Nigeria equalised with an Odion Ighalo penalty awarded after a VAR review.
Gambian referee Bakary Gassama initially dismissed Nigerian penalty appeals when a Peter Etebo shot struck the arm of Aissa Mandi but reserved that decision, with Ighalo sending Rais Mbohli the wrong way from the spot for his fourth goal in the competition.
Just as extra time began to look likely, Mahrez blasted in from 20 yards with the last kick of the match to send the Algeria through to their first final since lifting the trophy for the only time in 1990.
The team will take on Sadio Mane's Senegal for the title on Thursday, in a repeat of a group stage clash they won 1-0. Earlier on Sunday, Senegal beat Tunisia thanks to an extra time goal.
"We are very happy to be in the final of the Africa Cup of Nations because it is something very special," said Mahrez.
"It was our goal to do it for the people and for our families. We know they are behind us all the way. It's my most important goal for the national dream. Yes, it's my dream to win it and hopefully we will be able to."
Algeria supporters filled most of the lower tier at one end of the ground, dwarfing a small section of Nigeria fans, but there were large swathes of empty seats at the 75,000-capacity Cairo International Stadium.
Leading scorers in the tournament and considered by many to be the most impressive side, Algeria quickly asserted themselves as Ramy Bensebaini headed narrowly over before a wicked Youcef Belaili cross nearly lead to a goal for Baghdad Bounedjah.
Hesitant defending from Kenneth Omeruo just outside his own area then allowed Bounedjah to nip in, but the Al-Sadd striker could only shoot tamely at Daniel Akpeyi.
Seemingly having moved on from the penalty miss that reduced him to tears in the last round, Bounedjah was consistently proving a nuisance to a nervy Nigeria backline with Jamilu Collins relieved to see a toed clearance land on the roof of the net.
Nigeria countered intermittently as Ighalo dragged wide after Mahrez was caught in possession, but the Manchester City winger promptly atoned as Algeria made the breakthrough on 40 minutes.
After gathering the ball on the right Mahrez danced past Collins before sending over a cross that flicked off the left-back and struck a helpless Troost-Ekong in the midriff before tricking over the line.
Although Algeria’s Ismael Bennacer rattled the bar in stoppage time, Mahrez won it at the death with a thunderous strike into the top corner.
AFP contributed to this article.