With the game seemingly heading for a replay, Andy Carroll picked out his strike partner Diafra Sakho with just nine minutes left to head the Hammers through.
The League One high flyers looked like the Premier League team in the opening period as they played neat, intricate football to try and break the Premier League side down.
Twice in the first half the visitors had to clear the ball off the line from Matt Smith headers, with Carroll’s efforts underneath his own crossbar especially impressive.
After the break the pace of the game slowed somewhat as West Ham started to get a foothold in the match.
Sakho clipped the top of the crossbar with a thunderous strike from a tight angle as it looked like the visitors would be frustrated by the determined League One side.
However, the Senegalese striker arrived in the right place at the right time after superb work from Carroll to pick him out to snatch victory for the Sam Allardyce’s men as they continued to impress this season.
Right from the word go, the home side showed why they are flying high in League One, and actually looked like they were the Premier League side as Sam Allardyce’s men struggled to cope with their pace on the counter.
The first of Smith’s chances came in just the fifth minute, as he looped a header form a corner over Adrian in the West Ham goal, but Mark Noble got behind his ‘keeper to head away.
West Ham struggled to get out of their own half early on as the Robins continued to dominate. Luke Freeman was the instigator of all that was good about the hosts, and he was inches away on several occasions from finding that killer pass.
Smith then thought he had broken the deadlock with another powerful header, but Carroll brilliantly got his head to it to divert Smith’s effort over the bar.
Carroll was then at his favoured end of the pitch, getting on the end of a firm Carl Jenkinson cross, but his stab at goal was well saved by an otherwise untested Frank Fielding in the home goal.
After the break the visitors came into the contest much more as the League One side tired. The arrival of Sakho and Morgan Amalfitano added more impetus to the Hammers attack, and along with Carroll, they started to cause the hosts some problems.
Stewart Downing fired over the bar as he arrived late in the box before Sakho came mightily close to breaking the deadlock.
Picking up the ball in a wide position, Sakho flicked the ball over his own head and unleashed a ferocious effort at goal, which beat Fielding, but clipped the top of the crossbar.
The Senegalese hitman wasn’t to be outdone however, but the plaudits must go to Carroll for the assist for West Ham’s winner.
The former Liverpool striker brought a bouncing ball under control and clipped a perfect cross to the back post which picked out an unmarked Sakho, who found the roof of the net from close range.
Smith again looked most likely to get on the scoresheet for the home side, but his header in the dying moments flew just wide with Adrian struggling to get across.
The result sees West Ham avoid being another Premier League scalp on a weekend of shocks, but the Robins can be proud of their efforts, as they more than held their own against superior opposition.