The City winger, who completed the full 90 minutes and earned the Man of the Match award, struck a wonderful effort just before the hour mark in Cairo, doubling the lead after Youcef Belaïli had broken the deadlock in the first half.
Substitute Adam Ounas added the icing to the cake, adding a third on 82 minutes to effectively kill the tie.
READ: Angelino | 11 things you might not know...
WATCH: Inside City | Rodri’s first day
GALLERY: Behind-the-scenes | City’s 2019/20 PUMA away kit shoot
SHOP: City’s 2019/20 PUMA kits
Captain Mahrez wrote his name onto the scoresheet with a superbly-taken effort, delightfully plucking Ismael Bennacer’s cross out of the air to create space for himself before side-footing a controlled finish past Ibrahim Kone – a moment of real quality.
The triumph also continued Algeria’s 100% record in the tournament, with four wins from four, seven goals scored and four clean sheets.
Lining up against a side who had scraped into the last 16 with one win against ten-man Burundi, one draw and a defeat in the group stage, Algeria headed into the clash odds-on but wary of upsets with several favourites having already been eliminated.
Earlier in the day, Madagascar – competing in the tournament for the first time – claimed a shock result, defeating Congo on penalties after a 2-2 draw in normal time.
Managed by former City player Djamel Belmadi, Algeria would have no such drama, producing a dominant display in a fiery contest to book their place in the quarters.
Baghdad Bounedjah had already seen a goal ruled out for offside for the 1990 Champions before Belaïli opened the scoring, playing a neat one-two with Bounedjah before curling into the far post. There had been a touch of controversy regarding a foul throw in the build-up but the goal stood.
With the lead, Algeria rarely looked like relinquishing it, particularly after Mahrez bagged his second goal of the tournament to extend the advantage with a piece of individual brilliance.
The City man was unfortunate not to double his personal tally, thwarted by Kone on 66 minutes, but Ounas sealed progression with eight minutes of normal time remaining, sliding in to divert Youcef Atal’s through-ball home, and Algeria registered their first knock-out stage victory since lifting the trophy.
They face either Mali or the Ivory Coast in the last eight on Thursday 11 July, after the pair lock horns in the Round of 16 on Monday 8 July (5pm BST).