Darwin Nunez scored a fine goal as Liverpool saw off West Ham to extend their unbeaten run to 18 games.
Mohamed Salah gave Liverpool the lead against the run of play with a penalty after he was brought down by Nayef Aguerd.
Jarrod Bowen levelled for West Ham with an excellent stooping header to meet Vladimir Coufal's cross.
Soon after Curtis Jones had a goal ruled out for Liverpool for offside.
Nunez put them ahead with a difficult hooked volley from Alexis Mac Allister's clipped ball over the top.
The Hammers played well in stages but never created a clear-cut chance to equalise.