Jurgen Klopp's unbeaten side looked set to drop a precious two points in their dogged pursuit of City but they benefited from a bizarre error from Everton goalkeeper Jordan Pickford to win 1-0 and continue their Anfield hex over their city rivals.
Unai Emery's Arsenal are now 19 matches unbeaten in all competitions after their thrilling 4-2 victory against Tottenham at the Emirates lifted them to fourth, above fierce rivals Spurs on goal difference.
Chelsea recovered from the disappointment of losing their first match of the Premier League season to Spurs last week to beat Fulham 2-0 and climb to third in the table.
Liverpool started the Merseyside derby determined to salvage some pride after their midweek defeat to Paris Saint-Germain left their Champions League hopes in the balance.
There were chances for both teams in an entertaining encounter but the match appeared to be heading for a goalless stalemate as the seconds ticked away.
But then out of nowhere, England's Pickford made a terrible error.
He misjudged a looping, miskicked shot from Virgil Van Dijk, appearing to push the ball upwards before it bounced on top of the bar and into the path of substitute Divock Origi.
The Belgium forward had the simple task of heading into the empty net to spark scenes of ecstasy at Anfield, with Klopp racing onto the pitch to celebrate.
Pickford apologised for his blunder but gave a different version of events.
"The ball spun and as I tried to flick it over, my hand hit the bar," he said. "I think it is the Everton luck when we come to Anfield."
Klopp apologised on TV for his celebrations and also explained he had said sorry to his opposite number Marco Silva after the win, which closes the gap to City to just two points.
"What can I say about it? I didn't want to run," said Klopp. "It was not in my plan. I didn't want to run to Ali (goalkeeper Alisson), I couldn't stop obviously. Not cool, but it happened."
Silva disputed Klopp's version of events, however. "He didn’t apologise to me," he said. "To be honest, I didn't see so I don't know what he did and how he did it."
- Arsenal guts -
Earlier, Pierre-Emerick Aubameyang's penalty gave Arsenal an early lead in the north London derby before Eric Dier's header and a Harry Kane spot-kick handed Tottenham the lead at half-time at the Emirates Stadium.
But Aubameyang's superb long-range equaliser sparked a second half surge from the Gunners. Alexandre Lacazette came off the bench to put Arsenal ahead and Lucas Torreira sealed the points with his first goal for the club.
Capping a miserable day for Jan Vertonghen, the Tottenham defender was sent off in the closing stages after earlier giving away Arsenal's penalty.
"It is a very big match for our confidence. Now we have to continue our process," Emery said. "It is a very big victory. We give this to our supporters because it's a very special match against Tottenham."
Emery has injected life into an Arsenal side that had stagnated in the final years of Arsene Wenger's reign but losses to Manchester City and Chelsea and a draw with Liverpool had raised questions about the team's ability to compete with their biggest rivals.
In the first match of the day, a nervy Chelsea scored early through Pedro and late through Ruben Loftus-Cheek to see off London neighbours Fulham.
Sarri said he could see tension in his players at Stamford Bridge, even though last week's defeat at Spurs was their first loss in the league this season.
On Saturday, Manchester United dropped points in a 2-2 draw against struggling Southampton and are now eight points off fourth place, still with a negative goal difference.
Jose Mourinho's United host Arsenal on Wednesday knowing they cannot afford to lose as their chances of qualifying for next season's Champions League look increasingly remote.
City beat Bournemouth 3-1 to move to record their 12th win in 14 matches, with 38 points in the bag already and a goal difference of +37.