Pep Guardiola's side came into the game knowing victory would put them on the brink of the title but having fought back from two goals down, they had to settle for a draw after Mahrez's 86th-minute spot-kick was repelled by Fabianski.
West Ham had threatened to blow the title race wide open as the brilliant Jarrod Bowen scored two breakaway goals in the first half at an emotional London Stadium, where captain Mark Noble later came off the bench for his last home appearance for the club.
City piled on the pressure in the closing stages and looked set to complete the turnaround when Craig Dawson was penalised for a foul on Gabriel Jesus in the West Ham box following a VAR review, but Fabianski guessed correctly to keep Mahrez's penalty out.
City moved four points clear of Liverpool and will be crowned champions if Jurgen Klopp's side lose their game in hand against Southampton, live on Sky Sports on Tuesday, but any other outcome at St Mary's Stadium will ensure the race goes down to the final day.
Title race permutations
Man City are up to 90 points with one game to play. But Liverpool, with their game in hand, can still get to 92.
If Liverpool win at Southampton on Tuesday, City will need to at least match Liverpool's result against Wolves when they host Aston Villa at the Etihad to guarantee the title.
Defeat for Liverpool at St Mary's would mean City are champions.
A draw on the south coast would almost be enough for City, too. Liverpool would then require a huge win over Wolves and a Man City defeat to take the crown.
How West Ham held City on emotional day
There was a stirring tribute to Noble before kick-off as the club captain took to the pitch to soak up the applause of the home supporters, who held up a giant tifo depicting his name and number.
The electric atmosphere seemed to lift Noble's team-mates when the action got under way and West Ham fashioned an early scoring opportunity when Dawson sent a header onto the roof of the net from a Pablo Fornals cross.
City soon began to dominate possession, creating a flurry of half-chances and also seeing a penalty appeal waved away after Kurt Zouma appeared to catch Gabriel Jesus, but the hosts were primed for opportunities to spring forward and that's how the opener arrived.
Fernandinho was caught out of position as he went up for a header with Michail Antonio, and Fornals reacted by lifting an excellent first-time pass into the space behind him, where Bowen raced through on goal having lost Oleksandr Zinchenko.
The 25-year-old then kept his cool to take the ball around Ederson and slot an angled finish into the unguarded net as the London Stadium erupted in celebration.
Gabriel Jesus was inches away from levelling for City soon afterwards when his low effort from inside the West Ham box flashed past the post following a driving run by Zinchenko.
But West Ham continued to hold firm and Zinchenko was exposed again at the other end as the hosts doubled their advantage when Bowen latched onto Michail Antonio's clever, chipped pass before beating Ederson for a second time.
The goal left City with a mountain to climb in the second period but their response was immediate as Grealish's volley from the edge of the box took a nick off a West Ham player on its way into the net.
Fabianski then denied Jesus and Bernardo Silva as the visitors went in search of a leveller but there were chances for the Hammers too.
Bowen fired into the side-netting following another error by Zinchenko and Antonio, otherwise excellent for West Ham, then spurned a one-on-one chance after latching onto a poor Fernandinho backpass and lifting the ball well wide.
City swiftly punished that miss as Mahrez's wicked delivery was diverted past Fabianski by Coufal, who lay with his head buried in the turf, the equaliser setting up a grandstand finale.
David Moyes threw on Noble, who received another huge ovation from the home supporters, but it seemed he would be signing off with a defeat when referee Anthony Taylor pointed to the spot for the penalty having consulted the pitchside monitor
But Fabianski, who had already made a number of important saves, got two hands to Mahrez's penalty, ensuring the title race remains alive - and West Ham, now two points behind Manchester United in sixth, remain in contention for a Europa League finish.
Guardiola hails comeback: It's in our hands
Man City boss Pep Guardiola told Sky Sports: "Great comeback. And a comeback against this team in this stadium with the way they defend and how strong they are was an incredible credit to the team.
"We played a really good game. We spoke at half-time and said if we score one goal, we'll be in the game, don't give up. Fortunately we scored early in the second half.
"One more week, one more game, with our people at home. I assure you something: it will be sold out in the Etihad Stadium and we'll do the best performance possible to win the game and win the title.
"It would have been perfect to win today but West Ham is fighting for Europa League and have made an incredible season. It's in our hands, that's good.
"It will not be easy. there will be a lot of emotions. We have to train calm and arrive fresh. We have one week. Some days to recover. And we will do everything in that game to win the title."
Noble grateful for 'emotional' send-off
West Ham's Mark Noble told Sky Sports: "We agreed we wouldn't do [a sentimental sub] it was only to be in the best interests of the football team and West Ham.
"Kevin Nolan came over to me at half-time and said the gaffer's going to need you at about 70 minutes and it's thank you to Lukasz that he saves the penalty right at the end and makes the day that little bit more special."
On his emotional reception before the game, Noble added: "I tried to keep it together at first but the emotion got the better of me.
"It was fantastic send-off from the fans today. It's been a long lead-up to this game because I announced it last season and what a season it's been.
"I couldn't have asked for a better send-off. Very rarely at this level of football do you get to make your own exit and I've been lucky enough to do that.
"It's the right time now to go and spend time with the family. I'll always be associated with West Ham.
"They've made it clear to me, the board, the owners and the boss that they want me to stay but I'm definitely going to have a holiday and see what happens in the future."
Analysis: City show powers of recovery
The London Stadium was a cauldron of noise as the home supporters, already in buoyant mood amid emotional tributes to their departing captain Noble, jubilantly celebrated Bowen's second goal shortly before half-time.
This was a game in which most expected Manchester City to move six points clear of Liverpool, putting themselves on the brink of the title with one game remaining. But West Ham had other ideas.
Bowen's double put City in unfamiliar territory. They had not trailed a Premier League game since February - let alone trailed by two goals. But this team have a steely side in addition to all their quality.
Injuries had robbed them of Ruben Dias, John Stones and Kyle Walker, leaving them with a makeshift backline which West Ham succeeded in exploiting, but their response was immediate after the break as Grealish pulled one back before Coufal's own goal brought them level.
They walked off the pitch at the end of it all in deflated mood despite their efforts, Mahrez's botched penalty making the draw feel more like a missed opportunity than a creditable comeback.
But the point may yet prove crucial in the title chase and it keeps their destiny in their own hands ahead of their final game of the season. Manchester City could have crumbled. Instead they showed powers of recovery in difficult circumstances. It may make all the difference.