Algeria have six points and will win the group as they cannot be overhauled by either Burkina Faso (three points) or Sudan (three) following the third round of fixtures in the pool due to the head-to-head rule.
The Burkinabe meet Sudan in their final clash on Wednesday, while Algeria take on bottom side Equatorial Guinea, who are eliminated.
Algeria were awarded a penalty just past the 20-minute mark when Rayan Ait Nouri was felled in the box by Ismahila Ouedraogo, and Mahrez made no mistake as he sent Herve Koffi in the Burkina Faso goal the wrong way.
Mahrez extended his record as Algeria's all-time leading scorer at the Cup of Nations with his ninth goal and is also the leading scorer in this edition so far having netted twice in the opening 3-0 win over Sudan.
The Burkinabe came close to an equaliser just before halftime when Pierre Kabore's close-range header came back off the post and Algeria were able to scramble the ball to safety.
Luca Zidane, son of France great Zinedine, showed good reactions to keep out a Lassina Traore header late on as Burkina Faso came close to an equaliser.
Earlier, Sudan profited from a late own goal to beat Equatorial Guinea 1-0, picking up their first points of the tournament.
Mohamed Eisa's free-kick in the 74th minute was cleared by Equatorial Guinea's Luis Asue but struck team-mate Saul Coco and ricocheted back past the despairing dive of goalkeeper Jesus Owono.
Gabon are facing an early exit from the tournament after slipping to a 3-2 defeat to Mozambique in their Group F clash in Agadir, which ended a 40-year wait for a victory at the continental finals for the southern African side.
Gabon have now lost their opening two games while Mozambique have three points from their two fixtures, the same number as Ivory Coast and Cameroon, who meet later on Sunday. If that match ends in a draw, Gabon will be eliminated.
In the late game, defending champions Ivory Coast took a lead that lasted only five minutes before Cameroon equalised to secure a 1-1 draw in their heavyweight clash.
Amad Diallo scored for a second successive game to open the scoring for the Ivorians in the 51st minute but full back Junior Tchamadeu levelled for Cameroon with the help of a deflection in the 56th minute at the Grande Stade Marrakech.
The countries, who have eight Cup of Nations titles between them, now share the lead in Group F with four points apiece, followed by Mozambique on three.