After being 1-0 down for most of the game, late strikes from Trent McClenahan and Daryl McMahon sealed a terrific comeback and ensured the Hammers will now face Arsenal or Aston Villa in the semi-final play-off.
The Blues were the better side in the first half and took a deserved lead on the half hour mark when a long throw led to a cross that was headed past Glenn Jackson from six yards out.
With Chelsea's quick passing movement and skilful style of play causing problems for Hammers, coach Tony Carr changed his team's approach at the interval, matching the opponents' midfield diamond formation and encouraging a more direct style of play in order to deny them possession.
The plan worked well as Hammers pushed Chelsea on to the back foot, but it wasn't until the arrival of substitute Ayo Akinsete on 75 minutes that Carr's team looked like making the breakthrough. The young winger added some physical presence to the attack and five minutes later came the equaliser.
A goalmouth scramble saw Elliott Ward's shot cleared off the line, but Australian defender McClenahan was on hand to poke home the loose ball.
A point seemed likely, but with just one minute of normal time remaining, Hammers claimed a stunning winner. Chelsea conceded a foul just outside the penalty area, the offender was subsequently sent off for his second bookable offence of kicking the ball away, and McMahon stepped up to blast the free-kick into the roof of the net.
With second-placed Fulham losing, the win confirmed Hammers' qualification to the knock-out stage with one game to spare.
Team: Jackson, McClenahan, Tattam, Ferdinand, Ward, Lumsden (Akinsete 74), Wright, Bunce (Collington 84), Cole (Blewitt 89), Pearson, McMahon. Subs unused: Sealey, Laws.