Despite the two sides having hugely different fortunes heading into the tie, it was anything but a routine victory for the table-topping Reds, who had to dig deep for victory.
Gini Wijnaldum put Liverpool ahead inside the opening ten minutes, only for Issa Diop to put the visitors ahead from a corner at the Kop end.
Jurgen Klopp's side dominated possession but fell behind as the Hammers took a shock lead after half-time, with Pablo Fornals turning home from Declan Rice's cross into the box.
Liverpool then showed exactly why they remain unbeaten in the Premier League this season as Andy Robertson found Mohamed Salah just inside the penalty area. The Egyptian's shot straight at Lukasz Fabianski squeezed through the goalkeeper's legs as the Reds drew level.
With a little under ten minutes to go, the Reds went back ahead and sealed the game as Joe Gomez's deflected shot fell to Trent Alexander-Arnold, who nudged the ball towards Sadio Mane to comfortably turn into the back of the net.
The result saw Liverpool move to 79 points at the top of the Premier League table, with the Reds needing just 12 more points to seal their first league title in 30 years.
Slide through our gallery below for all the best snaps from Anfield.