Defeat for City leaves Guardiola's team four points behind leader Arsenal, which won 1-0 at Leeds earlier in the day.
Victory provides hope for Liverpool that it can recover from an unconvincing start to the season, which left it 13 points adrift of City before kickoff.
Despite Liverpool's struggles so far this term, this still felt like a meeting of the Premier League's elite after the two teams' dominance in recent years.
That was underlined by an even first half, with both having chances to take the lead.
Andy Robertson fired Liverpool's best chance over, while Erling Haaland forced two saves from Alisson and might have done better with at least one close range header.
The game burst into life after the interval when Salah raced through on goal and looked certain to score.
But the Egyptian's effort went wide of the post, with replays later showing Ederson had provided a crucial touch.
That went unnoticed by the officials and City restarted the play with a goal kick, from which Foden eventually found the back of the net.
With the visiting fans rejoicing, VAR invited referee Anthony Taylor to review the incident on the pitch-side monitor.
Walking past a furious Guardiola, who remonstrated wildly, Taylor ruled the goal out for a foul on Fabinho in the buildup.
City's manager was furious, repeatedly turning to the Anfield fans behind the dugout to gesticulate.
The crowd delighted in his anger and erupted shortly after when Salah fired Liverpool in front.
When Alisson collected an inaccurate free kick from Kevin de Bruyne, the goalkeeper then launched a kick downfield to perfectly pick out his teammate.
This time Salah made no mistake with his finish.
There was still time for more drama when Klopp raced out of his technical area to appeal a decision, leading to him receiving a red card.
Substitute Darwin Nunez might also have doubled Liverpool's lead when making a mess of a late chance with only Ederson to beat.
Arsenal hang on for win over Leeds
Arsenal held on for a scrappy 1-0 win over Leeds in an eventful match brimming with controversy today to guarantee staying top.
Leeds missed a penalty and had another overturned during a review in a game that was delayed for more than 30 minutes after an electrical fault at Elland Road led to the players coming off just two minutes in.
After it resumed, Bukayo Saka broke the deadlock in the 35th minute when the England forward smashed the ball high into the net from close range after receiving a pass from captain Martin Odegaard.
Leeds sent on forward Patrick Bamford to start the second half and the change looked to be an inspired one. The Englishman put the ball in the Arsenal goal within minutes only for it to be ruled out for a push on Arsenal defender Gabriel.
With Leeds pressing, Arsenal defender William Saliba gave away a penalty for handling in the area. Bamford stepped up but sent the ball wide.
The home side continued to pressure the league leaders and appeared to have secured another opportunity to equalise when referee Chris Kavanagh sent off Arsenal's Gabriel for lashing out at Bamford and awarded a penalty in stoppage time.
However, he overturned both the sending off and the penalty award after reviewing footage of the incident at the pitchside monitor.
Arsenal has now won nine of the club's first 10 league matches to extend its stay at the top of the table. The defeat leaves Leeds 15th but just a point off the relegation zone.
Mount, Kepa stand out as Chelsea beat Villa
Mason Mount and Kepa Arrizabalaga were Chelsea's stars as they helped to maintain Graham Potter's unbeaten start with a 2-0 win over Aston Villa.
Mount bagged a brace at Villa Park in front of watching England manager Gareth Southgate.
But the visitors needed goalkeeper Kepa to produce two stunning first-half stops to deny Jacob Ramsey and Danny Ings with Chelsea on the ropes.
The Blues have now won their last five games in all competitions — keeping four clean sheets — and consolidated fourth spot in the league.
Defeat was harsh on an improved Villa, which rattled Chelsea but slipped closer to the drop zone. Manager Steven Gerrard joined Villa when the club was 16th and two points above the relegation zone. It's now 16th and a point above the bottom three almost 12 months into his reign.
Chelsea was gifted a sixth-minute lead thanks to calamitous defending from Tyrone Mings.
Ramsey hardly covered himself in glory as he allowed Ben Chilwell to get past him and a half-hearted tackle only helped the ball loop toward Mings. The defender was alone but completely miscued his header and it spun backwards for Mount to volley past an exposed Emi Martinez in the Villa goal.
Chelsea, without the injured Reece James and Wesley Fofana, was vulnerable at the back and needed an outstanding save from Kepa to stay ahead after 21 minutes. Ollie Watkins wriggled free on the left and cut back for John McGinn to fire at Kepa, the ball ran to Ramsey to force the goalkeeper into a brilliant low stop, turning the strike onto the post. He then recovered to brilliantly save from Ings, although the striker was flagged offside.
McGinn tested Kepa again when he muscled Thiago Silva off the ball only to shoot at the goalkeeper.
Kepa saved his best for the 33rd when Leon Bailey got the better of Chilwell and stood up a cross for Ings four yards out. It looked a certain goal as the striker got between Silva and Trevoh Chalobah but Kepa stuck out an arm to brilliantly turn the header over.
Watkins glanced wide before Mount delivered a sucker punch after 65 minutes. He was taken down by Mings 25 yards out and fired in a brilliant free kick that beat Martinez.
Manchester United loses ground
Manchester United lost ground in the race for the top four after being held by Newcastle in a 0-0 draw.
With fourth-place Chelsea winning 2-0 at Aston Villa, the London club moved three points clear of United in fifth, with Erik ten Hag drawing for the first time since taking charge at Old Trafford.
Substitute Marcus Rashford could have secured a late win for the home team but Newcastle held on for the point after the forward failed to convert Casemiro's cross in the fifth minute of stoppage time.
Newcastle looked dangerous in the first half, with Callum Wilson seeing an early penalty appeal ignored before Joelinton hit the crossbar and sent his follow-up onto the post.
In the second half United improved and Cristiano Ronaldo saw two goals ruled out.
Sean Longstaff's challenge on Jadon Sancho was among a string of dismissed penalty appeals.
Groans greeted the unsatisfactory conclusion of an afternoon that had started with cheers for former United manager Alex Ferguson as he made presentations to two of his finest signings.
Ronaldo was given an engraved plate after scoring his 700th club goal last weekend, with David De Gea receiving a plate to mark the fact Sunday was his 500th United appearance.
Newcastle could have been celebrating a 24th-minute goal when Kieran Trippier's free kick struck the wall, but the right back reacted quickly to lift a cross to Joelinton, who headed onto the crossbar.
De Gea was on the ground as Joelinton met the rebound, only to head onto the post.
Rice earns West Ham draw at Southampton
Declan Rice denied Ralph Hasenhuttl a vital win as West Ham drew 1-1 at Southampton.
The Saints manager had come under increasing pressure after a run of four straight defeats in the league.
A first Premier League goal from Romain Perraud gave Southampton hope of a victory that would have lifted it out of the bottom three until Rice's intervention.
The hosts took the lead in the 20th minute when Tomas Soucek sliced an attempted clearance from a throw-in. Referee Peter Bankes got in the way of Jarrod Bowen as he tried to intercept the ball before Perraud hit a low drive which deflected in off Ben Johnson.
West Ham's equaliser arrived in the 64th courtesy of the Hammers skipper.
Rice played a one-two with substitute Said Benrahma before the England midfielder bent a superb effort past Gavin Bazunu from the corner of the box.
Hasenhuttl, clearly needing to stem the tide of West Ham attacks, sent on four substitutes: Stuart Armstrong, Sekou Mara, Samuel Edozie and Ibrahima Diallo.
The changes almost paid off but Diallo's long-range shot flew narrowly over and Lukasz Fabianski saved from Edozie.