Chelsea were knocked out of the EFL Cup on their first visit to the London Stadium, where rival fans clashed in violent scenes towards the end of the match.
Goals from Cheikhou Kouyate and Edimilson Fernandes gave the Hammers a deserved place in the quarter-finals.
Kouyate got in front of John Terry to head Mark Noble’s 11th-minute cross beyond keeper Asmir Begovic and into the far corner of the net.
And Fernandes’ left-footed shot – his first goal for West Ham – put them in control.
Gary Cahill tapped in a consolation goal for Chelsea in the final seconds.
The Blues had made a lively start and captain Terry, back in the side following a recent injury, nudged the ball over the bar from Willian’s early corner.
N’Golo Kante then had a shot saved by keeper Darren Randolph from a similar position to which the Frenchman scored in Chelsea’s 4-0 thrashing of Manchester United on Sunday.
But it was the home side who drew first blood.
And they went close to doubling their lead when Michail Antonio shot narrowly wide after the ball ran for him following a challenge by Kante on Dimitri Payet which the West Ham playmaker felt warranted a penalty.
At the other end, Nathaniel Chalobah saw a long-range effort tipped over by Randolph, who also kept out a shot from Michy Batshuayi.
West Ham remained a threat and Chelsea were almost punished following a lapse by David Luiz.
Antonio squirmed away from the Brazilian and teed up Manuel Lanzini, who dragged a shot wide of the target.
Begovic was called into action twice before the interval, keeping out strikes from Payet and Pedro Obiang.
With the east London side on top, Batshuayi missed a great chance to equalise against the run of play in the final minute of the first half when he scooped the ball over the bar after being set up by Oscar, who went close with a low shot moments later.
Chelsea were on the back foot again immediately after the restart and Antonio got away from Terry and found Payet, who was denied by a fine save from Begovic.
However, Begovic was unable to rescue the visitors a couple of minutes later.
After Chelsea failed to clear their lines, the ball fell to Fernandes near the edge of the penalty area and the Swiss youngster’s shot went through Terry’s legs and into the bottom corner.
Blues boss Antonio Conte responded by sending on Diego Costa and then Eden Hazard, who were involved in three opportunities Chelsea had to score before Cahill eventually did.
Costa found space in the area and pulled the ball back for Willian, whose scuffed shot evaded the lurking Hazard.
Costa also threaded a pass through for Hazard, who fired against the outside of the near post.
And Costa missed a late chance when he dinked the ball past Randolph but wide of the same near post after being put through by Willian.
Chelsea (3-4-3): Begovic; David Luiz, Terry, Cahill; Azpilicueta, Kante, Chalobah (Hazard 63), Aina (Pedro 67); Willian, Batshuayi (Costa 54), Oscar.
Subs not used: Eduardo, Alonso, Solanke.
This post was last modified on 28/10/2016