The win is the Londoners’ first over Liverpool since the 2015/2016 season and also Jurgen Klopp side’s first loss in 25 games.
Had they won, they would have made a club record of 26 games unbeaten and a move into second place with just a point behind Chelsea.
The Hammers went into the game after a disappointing 2-2 draw with Genk in the Europa League on Thursday while Liverpool had defeated Atletico Madrid 2-0 in the UEFA Champion League.
David Moyes’ side took the lead controversially when Allison failed to deal with a corner from Pablo Fornals as he was under pressure from Angelo Ogbonna.
Liverpool pressed hard immediately for the equaliser, but Diego Jota could only head inches over the bar moments later.
The equaliser came when Alexander-Arnold scooped a fantastic free kick just before half time.
West Ham went back into the lead later in the second half when Fornals broke through and placed the shot which Alisson failed to keep out
Kurt Zouma headed in what confirmed the win moments later although Divock Origi slammed home a half volley late on to pile pressure in the closing moments.
Meanwhile, Arsenal moved into top 5 when they beat Watford 1-0 in an eventful encounter at the Emirates stadium.
Bukayo Saka had a goal disallowed in the fifth minute for offside before Pierre Emerick Aubameyang missed a penalty in midway into the first half.
Emile Smith Rowe scored in the 56th minute, making him the fourth Arsenal aged 21 or younger to have scored in three consecutive Premier League appearances after Nicolas Anelka, Jose Antonio Reyes and Cesc Fabregas.