With the scores locked at 1-1 deep into the game after Gabriel Jesus's opener had been cancelled out by Dominic Calvert-Lewin, City were in need of a moment of magic to change the game.
It was provided by man-of-the-match Mahrez who curled home an exquisite 71st minute free-kick to restore our lead.
Victory was then confirmed six minutes from time by Sterling who, on his 200th appearance for the Club, lashed home a drive off the bar which was awarded by goal-line technology and which was the 100th strike of the winger's career.
It proved a gripping encounter at Goodison with City also indebted to goalkeeper Ederson who produced an incredible late save, with Pep Guardiola's side 2-1 ahead, to deny Yerry Mina's goalbound header.
But the champions kept our composure to secure a precious three point haul from a testing trip to Merseyside.
City were immediately onto the front foot with Mahrez warming up Everton ‘keeper Jordan Pickford’s palms with a stinging shot inside the first minute.
Seconds later Everton were forced into a change after Theo Walcott was felled by a Sterling cross which caught him flush on the face, the England winger being stretchered off after a six-minute delay and replaced by Alex Iwobi.
The prolonged break didn’t deter Guardiola’s side however and after a probing, patient start we were inches away from an 11th minute breakthrough.
Mahrez was the architect, his superb ball hit with the outside of his foot finding the unmarked Ilkay Gundogan just yards out, but the German’s shot rebounded back off the bar.
However, on 23 minutes the Blues did make the all-important breakthrough our dominant start merited.
The impressive Mahrez made initial inroads, bursting down the right flank before bringing the ball back inside for, who else, Kevin De Bruyne.
Our assist king duly whipped in a stunning curling ball – his eight assist of the season - for the onrushing Gabriel Jesus who showed both bravery and a goal poachers’ instinct to stoop and head home past Pickford.
The Toffees almost made an instant response with Ederson needing to be alert by blocking Gylfi Sigurdsson’s low drive at the second attempt.
It proved a warning sign as on 33 minutes the hosts were back on level terms.
Iwobi won a tussle in the centre of the box and the ball found Seamus Coleman free on the right side of the box.
His clipped cross-cum-shot evaded Ederson and the ball was already going over the line, but Dominic Calvert-Lewin made doubly sure with his head.
With Everton’s tails up, there was a big let-off for City on 41 minutes. Iwobi’s excellent pin-point pass evaded our defence and found Sigurdsson free in the middle of the box. Fortunately, the Icelandic midfielder mistimed his effort with Ederson gratefully gathering.
City though reasserted command of the game and almost summoned up a wonderful response just before the break.
More fine interplay between Mahrez and De Bruyne teed up Jesus on the left of the Everton box but this time the Brazilian’s effort was high and wide.
Seconds after the restart yet another sumptuous De Bruyne crossfield ball laid the foundation for Gundogan. Once again however, the German was denied, this time by Keane’s block.
Mahrez then turned provider putting in De Bruyne on the overlap but the Belgian could only fire into the side netting.
Ederson then produced a stunning reaction save to deny Everton as he clawed away Yerry Mina’s six-yard goal bound header with the Colombian completely unmarked.
More magic from Mahrez then unlocked the Everton defence, his slide rule pass finding Sterling who had timed his run to perfection, only to side-foot wide.
You felt it needed something special to make a difference. And that moment of magic was provided by Riyad Mahrez on 71 minutes.
After De Bruyne had been brought down on the edge of the box, the Algerian stepped up to power home a sublime free-kick into the left hand corner of the net for a quite sublime goal.
Everton weren't finished though and Ederson had to be alert to deny Calvert-Lewin with his left knee as the tempo increased.
And Ederson then produced a stunning save to deny Mira's 79th minute header, the Brazilian diving to his right to incredibly claw the goalbound effort away.
And with six minutes left City made the game safe when Raheem Sterling marked his 200th appearance for the Club by smashing home Sergio Aguero's pass, referee Michael Oliver ruling the ball had crossed the line after smashing down off the bar.
It was another landmark occasion for Raheem Sterling who was making his 200th career appearance for the Club.
Sterling has proved a key component in our success over the past two seasons.
The England winger was again a constant threat in possession and after being denied on a number of occasions, his patience was finally rewarded with his late strike which was the 100th of his career overall.
Riyad Mahrez has been in sublime form since the start of the season and the Algerian was once again at his mesmeric best at Goodison.
His vision and skill proved a constant thorn in Everton’s side all evening and his link-up play with Kevin De Bruyne in particular, constantly caught the eye.
And his sensational second half free-kick was no less than he deserved.
"It's always difficult here. First half we started incredible, the first 20-25 minutes, then we had problems to control Gylfi Sigurdsson in that position.
"But we created from wide areas in the second half and we had the quality of Riyad Mahrez for the goal.
"Everton have fast players, they caused a lot of problems at the back, so I'm delighted because we want to go for this league and try to win it again."
What it means…
Our fifth league win of the season means we stay five points behind leaders Liverpool who earlier beat Sheffield United 1-0.
BUZZIN 🚀🚀 pic.twitter.com/gN9yyAdRGU— Riyad Mahrez (@Mahrez22) September 28, 2019
City return to Champions League action on Tuesday night when we play our second Group C clash at home to Dinamo Zagreb. Kick-off at the Etihad Stadium is 8pm