There was injury time heartbreak as Dimitri Payet scored a 96th minute free kick to knock Stanley out of the EFL Cup at the third round stage.
Stanley, who had beaten Bradford and Burnley in earlier rounds, played superbly to keep out the Premier League side at the London Stadium and had chances to see off the Hammers.
But, with extra-time looming, sub Payet fired home a 20-yard free kick in front of 39,877 fans – with over 700 from Accrington, singing throughout the game.
Stanley performed superbly on the big stage and had the first chance on two minutes with captain Seamus Conneely's strike saved by former Reds loan keeper Darren Randolph.
The Reds settled quickly and while the Hammers launched a couple of early attacks, the visiting defence looked comfortable.
Janoi Donacien made a superb tackle on the edge of the area on 14 minutes to stop Simone Zaza running clean through on goal while a Sofiane Feghouli 40-yard free kick was straight at Elliot Parish.
Stanley were creating chances and on 19 minutes Sean McConville's left wing cross found Jordan Clark but he just couldn't make firm contact.
Then Billy Kee laid the ball back to John O'Sullivan on the edge of the area but he fired wide.
Stanley passed the 30 minute mark barely untroubled and Matty Pearson, with his head bandaged, got ahead of Zaza to stop the frontman having a chance.
The Reds limited West Ham to half chances in the first half and John Coleman would definitely have been the happier manager at half time.
Hammers boss Slaven Bilic brought on Manuel Lanzini and Payet at half-time and West Ham had the first chance with Zaza turning in the area and firing goalwards but it was comfortable for Parish.
However Stanley created the best chance in the game so far on 52 minutes when McConville got the ball to the left and forced a strong diving save out of Randolph.
Payet will have felt he should have done better after racing down the wing and into the Stanley box but, when he eventually passed, the Reds backline had got back to clear.
And Pearson pulled off a superb last ditch tackle to deny Jonathan Callieri as the game passed the hour mark with Stanley all-square.
Seamus Conneely fired just off-target for the Reds with McConville also narrowly wide with an effort with Coleman putting on Chris Eagles as they looked for the winner.
However, on 75 minutes, it took heroics from Parish to keep West Ham out as the keeper superbly kept out Zaza's close range strike with his legs.
Stanley then had to defend strongly with players putting their bodies on the line with both Mark Hughes and Rommy Boco coming on for the Reds.
Parish, one of the heroes of the Burnley win, kept out Pedro Obiang in injury time but couldn't stop Payet's winner.