Riyad Mahrez scored from a free kick in the fifth minute of injury time as Algeria beat Nigeria, 2-1, on Sunday and progressed to the Africa Cup of Nations final against Senegal.

Mahrez thundered his left-footed shot into the top corner as effectively the final kick of the game, settling the semifinal at Cairo International Stadium in stunning style.

Algeria took the lead on an own goal by William Troost-Ekong, but the score was evened when Nigeria was given a penalty for handball after a long video assistant referee referral by the referee, who had not initially awarded the spot kick. Nigeria took its opportunity — contentious as it was — as Odion Ighalo tied it at 1-1 from the spot.

But Mahrez, Algeria’s captain, scored at the very end, sending his team to its first final since it won its only African title nearly 30 years ago in 1990.