Liverpool arrived at the London Stadium knowing that if they avoided defeat they would extend their unbeaten run to 26 matches, beating the club’s all-time record set by Bob Paisley’s team in 1982.
They looked on course to do just that following a wonderful free-kick from Trent Alexander-Arnold.
But West Ham mean business as well this season and proved it when Pablo Fornals, whose corner had been palmed in by Reds keeper Alisson for the opening goal, broke away to score a second.
Kurt Zouma then headed a third and although Divock Origi pulled one back with seven minutes remaining, the Hammers held on for a famous victory.
West Ham took the lead in the fourth minute when Alisson, under pressure from Angelo Ogbonna as he leapt for the ball, touched Fornals’ corner into the net.
After a lengthy VAR review, for a possible foul and then handball, the goal was awarded, much to Klopp’s dismay.
Diogo Jota, starting in place of the injured Roberto Firmino, could have equalised on the half hour but sent his header from Jordan Henderson’s cross over the crossbar, while Alexander-Arnold’s volley was also too high.
However, with five minutes of the half remaining Liverpool were awarded a contentious free-kick on the edge of the area when Mohamed Salah went down under Declan Rice’s challenge.
West Ham lined-up an eight-man wall, complete with Fornals as the ‘draught excluder’, but Alexander-Arnold bypassed it with a simple one-yard pass to Salah to his right.
It left the England right-back with the simpler task of lifting the ball over Jarrod Bowen on the end of the wall, rather than the imposing Rice, Dawson and Tomas Soucek, and he curled a superb effort up and over while leaving Hammers keeper Lukasz Fabianski totally wrong-footed.
Michail Antonio passed up a glorious chance to put West Ham back ahead when he was sent clean through by Said Benrahma, only for his control to badly let him down at the wrong time, and Bowen was thwarted by a perfectly-timed Virgil Van Dijk challenge in the area in stoppage time.
At the start of the second half Dawson’s header from another corner came back off the crossbar, while at the other end Sadio Mane’s volley was kept out by Fabianski.
It was Bowen, a player Klopp readily admits he admires, who unlocked the Liverpool defence in the 67th minute after Dawson and Rice smuggled the ball away for West Ham from inside their own half.
The forward ran at the back-pedalling Liverpool rearguard, drawing defenders in, before slipping the ball to Fornals who ran through to fire past Alisson.
There was more to come. Antonio and Fornals were denied by Alisson before Bowen floated in a 75th-minute corner and the unmarked Zouma nodded it in at the far post.
Origi turned and fired home from 18 yards to set up a grandstand finish but Liverpool could not find an equaliser – Mane coming closest when he headed wide in stoppage time – and Hammers boss David Moyes celebrated a place in the top three and a first win over Klopp in eight attempts.