Phil Foden missed what turned out to be the decisive spot-kick as holders Manchester City were knocked out of the EFL Cup for the first time in five years on penalties following a 0-0 draw in normal time.
Alphonse Areola made a number of crucial saves as the Hammers frustrated City at the London Stadium across 90 minutes, forcing a penalty shootout to settle the tie.
Foden was the only player to miss from the spot, with West Ham scoring each of their five penalties - Mark Noble netting the first and Said Benrahma scoring the last.
David Moyes' side are now through to the quarter-finals, while City's remarkable run of progressing from their last 21 League Cup ties comes to an end.
The first half was a low-key affair, with Nathan Ake heading the best chance wide just before the break as City struggled to create chances against a stubborn West Ham side.
Shortly after the restart, Ilkay Gundogan spurned a glorious opportunity, steering wide of the far corner after being played through by Cole Palmer, before Arthur Masuaku stung the palms of Zack Steffen from a tight angle.
Areola was then called into action three times in the space of two minutes as he saved from Raheem Sterling and Kevin De Bruyne and then produced a superb stop to repel John Stones' header from close range as City sprung to life.
The Hammers goalkeeper was on hand to rescue his team again with seven minutes of normal time remaining, palming Oleksandr Zinchenko's ferocious strike over the bar.
Sterling headed straight at the goalkeeper with the last chance of the match, forcing City to a shootout that saw Foden critically fluff his lines.