A stunning Riyad Mahrez free kick in stoppage time has booked Algeria a place in the Africa Cup of Nations final, where they will face Senegal in Friday's decider.
Manchester City forward Mahrez sealed Algeria's 2-1 win over Nigeria with a thunderous left foot strike and effectively the last kick of the second semi on Sunday, while earlier Senegal beat Tunisia 1-0 after extra-time.
The Algerians went ahead when William Troost Ekong turned a Mahrez cross into his own net five minutes before halftime.
The Super Eagles equalised midway through the second half with Odion Ighalo converting a penalty awarded for handball following a lengthy VAR review.
But Algeria captain Mahrez won it at the very death to send his team to their first final since their only African title success nearly 30 years ago.
A bizarre own goal in extra time meanwhile in the first semi-final handed Senegal a 1-0 victory over Tunisia.
Sadio Mane's side won it in the 100th minute when Tunisian goalkeeper Mouez Hassen pushed a free kick onto the head of defender Dylan Bronn and the ball bounced back into his goal.
In a game of high drama, both teams missed penalties within a few minutes of each other in regulation time.
Tunisia should have gone ahead in the 75th but Ferjani Sassi's shot was weak and saved by Senegal goalkeeper Alfred Gomis.
Six minutes later Henri Saivet's low and hard strike was brilliantly deflected away by Hassen.
The most contentious moment of a scintillating game came right near the end after Senegal's Idrissa Gueye was initially penalised for handball in the area.
The Ethiopian referee awarded the penalty, but then changed his decision after using the VAR video review system.
Senegal are seeking their first Cup of Nations title, 17 years after their only previous appearance in the final.