Goals from Elliot Lee and Danny Whitehead were enough to send the Development Squad through to the last 16 of the Barclays Under-21 Premier League Cup after a hard-fought 2-1 victory over Bristol City.
After a quiet first half, Whitehead lit up the match as he burst through to score the opening goal of the game after 65 minutes with a well-placed shot.
Elliot Lee doubled the lead nine minutes later, heading home a Matthias Fanimo cross as the Hammers looked to be cruising through to the last 16.
The Robins had different ideas though and after Frazer Shaw bought down Wes Burns, the striker picked himself up to score the spot-kick and set up a nervy finale.
West Ham had goalkeeper Sam Howes to thank in the final five minutes as he twice denied Marley Bishop as they clung on for a cup victory.
The Hammers can now enjoy the prospect of a run in the inaugural year of this competition but were made to work hard for it against the Robins.
Nick Haycock's team could have been ahead as early as the first minute when Whitehead blazed a shot over the bar from inside the box. That would have set the Hammers on their way in what turned out to be a physical first half of few chances.
The chances that were created fell the visitors' way as Elliot Lee forced a fine save from Dave Richards after he worked a shooting opportunity just outside the box after ten minutes.
Lee came close again midway through the half as he attempted an audacious volley from long-range but saw his right-footed effort dip just over the bar.
The home side rarely threatened but were almost handed the lead when Howes mishandled a regulation shot, but much to the keeper's relief saw it bounce up over the crossbar.
Jordan Wynter and Pierce Mitchell both earned yellow cards after fouls on Whitehead and Fanimo respectively as a quiet first period came to an end.
The match sprung into life after the break with the home side going on the offensive. Mitch Brundle should have done better when he picked out Howes from five yards after controlling nicely in the box.
Next came a golden opportunity for Kevin Krans who looked certain to score as the ball fell at his feet six yards out after Brundle's knockdown, but the winger inexplicably struck his effort high into the stands.
He would be made to pay for his miss as in the 65th minute Whitehead slotted home following a lightning quick counter-attack.
Just nine minutes later and West Ham looked to be coasting as Fanimo's beautiful in-swinging cross located Lee at the far post who had an easy task to nod home.
No sooner had the visitors looked to be running away with it than the home side hauled themselves back into the match when Burns sent Howes the wrong way from the penalty spot after he had been bought down by Shaw.
Substitute Bishop had the chance to send the game to extra-time when he was found unmarked in the penalty area but his header was tame and Howes was able to hang on and secure the Hammers' passage to the next round.
West Ham United: Howes, Driver, Chambers, Harney, Shaw, Lletget, Whitehead, Bywater, Fanimo, McCallum, Lee
Subs not used: Baxter, Burke, Miles, Parfitt-Williams, Maguire
Bristol City: Richards, Mitchell, Brundle, Batten, Hall, Mafuta, Morrell, Wynter, Krans, Burns, Withey (Bishop 71)
Subs not used: Cable, Paice, Fry, Horgan