City's grip on the Premier League title was looking distinctly shaky at the break as the Hammers led thanks to Jarrod Bowen's well-taken double.
But Jack Grealish struck for the visitors four minutes after the re-start and Vladmir Coufal headed Riyad Mahrez's free-kick into his own net as City avoided defeat after coming back from two goals down in a top-flight game for the first time since 2012.
They even had a chance to win it five minutes from time but Lukasz Fabianski saved Mahrez's penalty after Craig Dawson had fouled Gabriel Jesus.
Guardiola looked devastated at that. But given the situation they found themselves in at the break, with Liverpool potentially having the chance to catch them when they play on Tuesday, the final outcome was positive for the visitors.
It certainly was for West Ham, who have qualified for European football through their league position in successive seasons for the first time in their history.
What's on the line in the final week of the Premier League season?
Follow reaction to West Ham v Man City and the rest of Sunday's Premier League action
Go straight to all the best West Ham content
Visit our Manchester City page
West Ham 2-2 Man City: Premier League title race is 'in our hands' - Pep Guardiola
City drag themselves out of trouble
It is a measure of the success Guardiola has had in this stadium that his first five visits all yielded victories - and a staggering total of 22 goals.
Now City have drawn on three successive visits - losing on penalties in the Carabao Cup earlier this season.
In the week they signed Erling Haaland, they found it impossible to hold West Ham's number nine, Michail Antonio, and were unsettled by Bowen's direct running.
Without Grealish's volley from Rodri's knock-down flicking off Craig Dawson's leg and over Fabianski, they might have been in for a very fraught second half.
As it was, they dominated possession and put the Hammers defence under so much pressure, it felt inevitable an equaliser would come. That Coufal provided it was unfortunate as the Czech did not have to dive at Mahrez's free-kick, which Fabianksi seemed to have covered.
Mahrez blew the opportunity to avoid a nervy final day - but, 10 years after Sergio Aguero's famous injury-time title winner, City fans do at least know that anything can happen if events start to conspire against them again.
Europa Conference joy for West Ham
West Ham's Jarrod Bowen scores his second goal against Manchester City in the Premier League
Jarrod Bowen has scored 12 Premier League goals this season, and has assisted another 12
This has been an excellent season for West Ham - with European qualification being welcomed by manager David Moyes, even if it ends up being the Europa Conference League.
Bowen, a Premier League player of the year nominee, has been one of the stand-out stars.
The former Hull man showed an impressive turn of pace to run on to Pablo Fornals' hooked long pass, sprint round Ederson and finish from an acute angle.
Bowen showed composure also when he ran on to Antonio's through ball and found the net again.
West Ham 2-2 Man City: David Moyes 'couldn't believe' Hammers were 2-0 up at half-time
However, had he pulled a cross back rather than try to score from an impossibly narrow angle shortly after Grealish had breathed new life into the game, West Ham might have got a rare home win over City.
Antonio also fluffed his lines when Fernandinho's woeful back-pass sent him through, chipping wide of Ederson and the City goal.
Hammers stalwart Noble says farewell
West Ham and their fans pay tribute to Mark Noble as the midfielder prepares to leave the club
Mark Noble will leave West Ham at the end of the season, having made 567 appearances for the club in all competitions
Mark Noble was 17 when he made his Hammers debut.
Born in Canning Town and growing up only a mile from Upton Park, Noble has been a fan all his life and other than short loan spells at Hull and Ipswich early in his career, has played for the club through the intervening 18 seasons.
West Ham were determined to make the most of Noble's final home game. His face adorned the side of the stadium, clearly visible on the walk up from the Westfield centre. A cake in his honour was left in the media room, with members of the press also given a letter from Noble thanking them for their support throughout his career.
The front page of the programme was dedicated to Noble, a distinctive number 16 shirt was laid on the pitch before the game, supporters applauded throughout the 16th minute.
Under the circumstances, it was hardly a surprise he was fighting back the tears as he came out to take the acclaim just before the teams emerged from the tunnel.
Moyes trusted Noble enough to bring him on near the end as West Ham secured their point, before Noble received the acclaim of virtually a full stadium that waited to hear his final farewell long after the whistle had gone.