Sadio Mane's 81st-minute strike ensured Liverpool overcame an almighty scare to beat a spirited West Ham 3-2 at Anfield and re-establish their 22-point lead at the top of the Premier League.
Jurgen Klopp's side trailed the Hammers with 22 minutes remaining, but goals from Mohamed Salah (68) and Mane ensured Liverpool equalled Manchester City's Premier League record of 18 consecutive league wins.
Georginio Wijnaldum's ninth-minute opener was immediately cancelled out by Issa Diop's third league goal in six games, before substitute Pablo Fornals completed a remarkable turnaround nine minutes into the second half.
But a dreadful error from Lukasz Fabianski allowed Salah to level, before Mane nudged Liverpool to within four wins of their first league title in 30 years.
Substitute Jarrod Bowen squandered a glorious chance to level moments after Mane was denied a second following a VAR offside review, with the result leaving 18th-placed West Ham still deep in relegation trouble, a point adrift of safety.
Liverpool: Alisson (6), Alexander-Arnold (9), Gomez (6), Van Dijk (7), Robertson (7), Keita (6), Fabinho (6), Wijnaldum (6), Salah (7), Firmino (6), Mane (7).
Subs: Oxlade-Chamberlain (6), Matip (n/a).
West Ham: Fabianski (6), Ngakia (7), Diop (8), Ogbonna (7), Cresswell (6), Rice (7), Snodgrass (7), Soucek (7), Noble (6), Felipe Anderson (7), Antonio (6).
Subs: Bowen (5), Fornals (7), Haller (n/a).
Man of the match: Trent Alexander-Arnold.
How Reds overcame Iron in the fire...
Prior to kick-off, the West Ham players warmed up wearing t-shirts in memory of Bobby Moore, who passed away 27 years ago on this day.
Manager David Moyes was seeking his first win at Anfield at the 16th attempt, but having failed to register a shot on target during last week's 2-0 defeat at Manchester City, Moore would have been dearly proud of the visitors' efforts on a night which belied the 55 points which now separate the two sides.
Liverpool were seeking to stretch their immaculate record of 13 wins from 13 home Premier League games, and they appeared set for a routine 14th victory when Trent Alexander-Arnold's superb cross was met by Wijnaldum in front of Robert Snodgrass to beat Fabianski low down to his right.
But 174 seconds later, West Ham were level as Snodgrass atoned for his lapse in concentration to find Diop at the near post as the Frenchman crashed his header beyond Alisson. It was the first goal Liverpool had conceded at Anfield since Richarlison's strike in the 5-2 Merseyside derby success on December 4, seven games ago.
Liverpool midfielder Naby Keita was given the nod to replace injured captain Jordan Henderson. The Guinea international was the only change from the midweek Champions League defeat away to Atletico Madrid.
West Ham made two changes with the injured Ryan Fredericks and Arthur Masuaku absent as Jeremy Ngakia - who made his only other senior appearance in last month's 2-0 home defeat to Liverpool - and Felipe Anderson came in.
The hosts nearly restored their lead when Alexander-Arnold was invited to shoot but his effort veered just wide, before Virgil van Dijk rose to meet the full-back's corner, but the Dutchman's header clipped the crossbar on its way over.
West Ham were dealt a blow within a minute of the restart when Tomas Soucek was forced off with a knock, but it was his replacement who duly put the visitors in front to silence Anfield and put Liverpool's 43-game unbeaten league record under severe threat.
Mark Noble found Declan Rice on the right and his low cross was swept home from 12 yards out by Fornals for only his second Premier League goal.
- How to watch Premier League highlights this season
- Get a Sky Sports Day Pass
- Find out more about Sky Sports
Klopp cut an anxious figure as Roberto Firmino headed over from Alexander-Arnold's set piece, but he was celebrating moments later, albeit in fortuitous circumstances, as Fabianski inexplicably allowed Salah's shot from Andrew Robertson's low cross to squirm through his legs.
Liverpool very nearly completed the turnaround six minutes later as Salah met Robertson's lofted cross once more, forcing Fabianski into a fine stop with his feet before Firmino was unable to nod home the rebound from an acute angle.
But West Ham were unable to hold on as Alexander-Arnold laid on his second assist for Mane to tap in from close range. There was still time for the Senegalese to be denied his second from another Alexander-Arnold cross following a VAR review for offside.
That left the door ajar for West Ham to launch one final attack, and Bowen very nearly provided a final twist as he was put through by Michail Antonio only to be denied by the onrushing Alisson as Liverpool breathed a huge sigh of relief.
What the managers said...
Liverpool boss Jurgen Klopp: "I think we had 70 per cent possession, but West Ham did some really good stuff with their 30 per cent. We started really well, but we weren't good with the second-ball situations. We have to pick them up much more often, and that was how the second goal came. We struggled in this situation and this gave them a good feeling.
"We lost a little bit of patience in the first half with what we did offensively. We wanted it a little too much, but we were forced to stay calm. The best goal we scored didn't count but sometimes you have to squeeze it and that's what we did tonight."
West Ham boss David Moyes: "I was pleased in a lot of aspects, we did a really good job. We're up against a really good opponent. I'm more disappointed that after getting ourselves in the position we did, that we didn't hang on to get a point. A lucky deflection goes against us and it makes it really difficult.
"I felt as if we'd done a good disciplined defensive performance at Manchester City. I felt tonight we could maybe try and go another way and see if we could get a result here, but it's not easy because Liverpool have so much ammunition. In the end, it wasn't good enough."
Analysis: Liverpool always find a way
Jamie Carragher: "This Liverpool team just do enough in every game. In 13 games this season, they've won by just the single goal.
"It was a brilliant game. Liverpool's performance in the last 20 minutes was just too much for West Ham to live with."
Gary Neville: "Liverpool always find a way. West Ham contributed enormously. They were unfortunate not to get a point. That's a template for them - they can take something from that."
Man of the match - Trent Alexander-Arnold
Liverpool had a brilliant last 20 minutes, but Alexander-Arnold had been the one consistent performer throughout the troublesome opening 70 minutes.
Neville described the 21-year-old as a "sensation" who has taken his game onto greater heights, and he played a pivotal role in dragging Liverpool over the line.
Alexander-Arnold has provided 25 Premier League assists, the joint-most by a Liverpool defender in the competition along with Stig Inge Bjornebye (25). Only Cesc Fabregas (20y 134d) and Wayne Rooney (21y 63d) have reached 25 Premier League assists at a younger age.
Reds keep their record in tact - stats
- Liverpool have won their last 18 Premier League games, equalling the all-time English top-flight record set by Manchester City between August-December 2017.
- Liverpool have won their last 21 home Premier League games, equalling the English top-flight record for consecutive home wins, set by the Reds themselves between January and December 1972 under Bill Shankly.
- Liverpool have scored 14 headed goals in the Premier League this season, more than any other side.
- Liverpool's Mohamed Salah has been directly involved in eight goals in six Premier League appearances against West Ham (6 goals, 2 assists).
- Liverpool's Sadio Mané has been directly involved in eight goals in his last six Premier League appearances against West Ham (5 goals, 3 assists), scoring in each of his last four against the Hammers.
Live Premier League
Liverpool travel to face Watford on Saturday, live on Sky Sports; coverage starts at 5pm with kick-off at 5.30pm.
West Ham host Southampton in the Premier League at the London Stadium on the same day at 3pm.