After dominating before the interval the hosts were hanging on at times in the second half and Mahrez had the chance to rescue a deserved point for last season's champions.
But his 77th-minute penalty, despite beating Willy Caballero, was correctly ruled out after City's players realised Mahrez had slipped while striking the ball and inadvertently made an illegal double contact.
It was the second lucky break for Pep Guardiola's side whose opening goal, scored by David Silva after 29 minutes, incensed Leicester's players because Raheem Sterling appeared to be offside when he swung a leg at the ball.
"The first goal was offside," Leicester keeper Kasper Schmeichel, who argued he was distracted by Sterling, told Sky Sports. "He (Sterling) was blocking my view. He's in the six-yard box and he is interfering because I can't see ball."
There was no doubt about City's second in the 36th minute. Leroy Sane was sent sprawling in the area by Yohan Benalouane and Gabriel Jesus fired the resulting spot kick into the corner.
Leicester were back in the match four minutes before halftime though when Shinji Okazaki smashed a sensational volley past Caballero from Marc Albrighton's cross.
City, who surprisingly left top scorer Sergio Aguero on the bench, were not clinical enough in front of goal and Leicester became increasingly dangerous in the second half.
Craig Shakespeare's side looked set to equalise when Gael Clichy tripped Mahrez in the area and referee Robert Madley had no hesitation in pointing to the penalty spot.
But Mahrez's scuffed effort was correctly ruled out as he kicked the ball against his standing leg and past Caballero.
Jamie Vardy also had a late chance for Leicester who sensed City's nervousness, but the hosts hung on to stay on course for a top-four finish with two games left.
They have 72 points while Liverpool, who also have two to play, have 70. Fifth-placed Arsenal have 66 points but have three games remaining, beginning later away to Stoke City.
"Well done. It's the first or second time I've seen that in my life," Guardiola said. "We have to look after our boots!
"We need one more game to be in the top four but it's in our hands. West Brom will be tough but hopefully we can be better than today. And we go to Watford."
Enter a name and e-mail address and we will e-mail this website link too them.