The Hammers took a 12th-minute lead when Lucas Paqueta, after playing a one-two with Michail Antonio, fired from 20 yards out past Liverpool goalkeeper Alisson.
West Ham thought they had gone back in front with Jarrod Bowen’s angled strike but the England forward was ruled offside by the video assistant referee to keep it at 1-1.
An unmarked Joel Matip scored what proved to be the winner in the 67th minute with a powerful header from Andy Robertson’s corner from the left.
There was a late scare for Liverpool when Thiago handled in the penalty area, with Hammers boss David Moyes furious that a decision was not awarded by either on-field referee Chris Kavanagh or Neil Swarbrick on video assistant referee duty.
At the final whistle Moyes confronted Kavanagh, still angry at the decision that cost his side an opportunity to earn a point.