West Ham moved above Liverpool into third place in the Premier League and stalled Jurgen Klopp's side's unbeaten run of 25 matches in all competitions.
An Alisson own goal just minutes into the game set West Ham on course. Trent Alexander-Arnold's sublime first-half free kick brought Liverpool back into it, but his goal was canceled out by a Pablo Fornals goal in the second half.
Kurt Zouma secured the win on 74 minutes with a header after a West Ham corner. West Ham hearts were sent racing, however, when Divock Origi scored a header late in the second half. It wasn't enough to give Liverpool the win, though.
"A great performance today from everyone, everyone in the crowd help us against a great team. It was an open game but we were more clinical and stayed strong at the end and dug deep," Zouma said after the game.
"Tactically we had to be spot on today, so when they lose the ball we knew they would be open. We had a plan and it worked out today.
"That is why I came here, to help the team grow up. Keep improving, and it is like a family here."
Liverpool's day started badly when Fornals took a corner which goalkeeper Alisson punched into his own net. There were protests from Liverpool about a foul on the keeper, but they were waved away by the referee.
There wasn't much sign of Liverpool equalising until Alexander-Arnold came up to take a free kick on 41 minutes. He curled the ball around the wall and past Lukasz Fabianski, who stood rooted to his spot.
West Ham caught Liverpool on the counterattack on 67 minutes after Sadio Mane lost the ball. Fornals took the ball from Jarrod Bowen and hit a low shot past Alisson, who got a hand to the ball but was unable to keep the shot out.
Bowen was on hand for the third goal in delivering a perfect corner into the box, which Zouma headed into the net as Alisson was once again caught off guard by West Ham's quick attack.
Origi pounced on a loose ball on 83 minutes to bring Liverpool back into the game, but they were unable to find an equaliser.
"[The long unbeaten run coming to an end] is the least of my problems. However long a run is, it will come to an end," Klopp said.
"There are couple of things that happened during the game that are difficult to take. If you don't take your chances, you're leaving things up to ref decisions."