Mahrez was the hero in Cairo, where the Manchester City star curled a 95th-minute set-piece past Nigeria goalkeeper Daniel Akpeyi to seal a dramatic 2-1 victory.
Algeria had initially led through William Troost-Ekong's own goal before Nigeria equalised via an Odion Ighalo penalty with 18 minutes remaining after a VAR review.
Mahrez and Algeria will now contest its first AFCON final since winning the tournament on home soil in 1990 when it faces Senegal.
After his man-of-the-match performance, Mahrez said: "It was a very tough game today against a strong team.
"We were one goal up and were in control before VAR's decision – they scored the penalty and in the last minute we converted our free-kick.
"We are very happy because to be in the final of the Africa Cup of Nations is something unbelievable.
"I think we have been very good in this tournament. We scored 12 goals and conceded two, that is the source of our confidence.
"We are looking forward to the final against Senegal. We played them in the group stage and we are expecting another tough game."
Algeria topped Group C ahead of Senegal, which lost 1-0 to the Desert Foxes on matchday two last month.