Joel Matip proved to be the match-winner with his second-half header at London Stadium clinching the three points for the Reds, who registered their third successive win.
Lucas Paqueta had put the Hammers ahead in the 12th minute but that effort was quickly cancelled out by a fine hit from Cody Gakpo.
Team news
Matip came into the starting line-up for the injured Ibrahima Konate in the only change from the weekend's win over Nottingham Forest.
Alisson, Alexander-Arnold, Matip, Van Dijk, Robertson, Fabinho, Henderson (Thiago, 59), Jones (Milner, 84), Jota (Diaz, 59), Salah, Gakpo (Nunez, 77).
Unused substitutes: Kelleher, Gomez, Elliott, Tsimikas, Carvalho.
First half
After a relatively tame opening period, the game sparked into life with impressive goals at either end.
The hosts went ahead when Paqueta found space in a central area after a pair of one-twos with Michail Antonio. He decided to fire at goal from just outside the penalty area and watched the ball fly into the back of the net.
However, it drew an encouraging response from Liverpool, who replied six minutes later.
A spell of pressure ended with Gakpo receiving possession on the half-turn from Trent Alexander-Arnold and driving a low shot from distance into the bottom left corner, kissing the post along the way.
Diogo Jota went close on two occasions to putting the Reds ahead before the break but flashed an effort over from close range and was unable to get on the end of a flick-on from Jordan Henderson.
Meanwhile, Virgil van Dijk was called upon to keep it level, as he poked Said Benrahma's cross behind for a corner just as Antonio looked destined to slide in and score.
From the resulting set-piece, the ball made its way to Antonio, though he could not react quickly enough to send a header towards goal.
Second half
West Ham thought they had retaken the lead 10 minutes into the second period.
Jarrod Bowen ran through on goal to meet Paqueta's ball and converted – only for the goal to then be chalked off for offside after VAR review.
But it was Liverpool who scored next to go ahead for the first time on the night.
Matip went close on the preceding corner but then produced an emphatic header from Andy Robertson's follow-up attempt in the 67th minute that left goalkeeper Lukasz Fabianski with no chance.
The Reds had something to hold onto now and Alisson Becker was sharply off his line to stop substitute Danny Ings from getting on the end of a threaded pass from Bowen.
West Ham threatened again with Maxwel Cornet and Bowen on the counter, as Tomas Soucek also headed over from a corner.
In the closing stages, they wanted a penalty for a handball against Thiago Alcantara but the officials – and VAR – did not agree and Jürgen Klopp's men held on for the win.