Robin van Persie scored in stoppage time as Manchester United remained in the FA Cup by the skin of their teeth and denied West Ham a famous win.
Tom Cleverley gave the visitors the lead when he sidefooted in before James Collins headed the equaliser, his first goal since returning to the club.
Collins gave the Hammers the lead with another header after the break.
With seconds remaining, Van Persie latched on to Ryan Giggs's through-ball to earn the visitors a replay.
No bore draws
- Only two of Manchester United's last 32 games in all competitions have ended level after 90 minutes
Although the Premier League leaders left it very late, there was something inevitable about the final act given the visitors' reputation for recovering the most unpromising of situations.
It was, however, heartbreaking for West Ham, who few would have said did not deserve their place in the fourth round following a mature performance.
Both sides fielded strong line-ups, while the visitors also named an impressive bench that included Rio Ferdinand, Antonio Valencia, Ryan Giggs, Ashley Young and Van Persie.
Welbeck took the Dutchman's place in the starting XI and his pace was a worry in the opening 45 minutes, but it was the speed of thought of strike partner Hernandez that led to the opening goal for United.
The Mexican has scored three in the last three, but was provider on this occasion when he darted down the right and delivered a pacey ball into the area for midfielder Cleverley, who opened his body up and guided a firm strike past Jussi Jaaskelainen.
His goal delighted the travelling fans and was warmly applauded by match attendee and ex-Old Trafford favourite David Beckham, to whom the goalscorer has been likened.
- In the last three competitive meetings between West Ham and Manchester United at Upton Park, four different Hammers players have scored a brace
A few moments earlier, defender Nemanja Vidic had a header cleared off the line by Daniel Potts, while West Ham's Alou Diarra saw his headed effort cleared from danger by a well-positioned Paul Scholes.
That aerial threat has benefitted Sam Allardyce's side this season, and five minutes after the opener they were level via those means when Collins scored his first goal since returning to the club from Aston Villa.
Joe Cole, making his second debut for the Hammers, roamed from wing to wing during the match and bent in a delightful ball from the left that was powered in by the centre-back off his forehead.
Ferguson's side made another lively start after the break and Cleverley should have at least hit the target instead of thrashing over when the ball came to him at the edge of the area.
Although the tactics seemed set right, Ferguson's defenders appeared to allow Cole more room than should have been afforded as the game went on.
Coming up to the hour, Cole was again allowed space to deliver. And on almost the same spot from which he had supplied the cross for West Ham's first goal, he found his partner-in-crime Collins, whose flicked header was beautifully directed into the corner.
Ferguson threw on the bigger guns - Van Persie and midfielder Antonio Valencia - to try to remain in a competition his side last won in 2004.
As four minutes of stoppage time were announced, the Hammers must have entertained the thought they had the 11-time winners beaten, but Van Persie changed all that as he brilliantly controlled Giggs's lofted ball and rifled in.
West Ham United
- 22 Jaaskelainen
- 05 Tomkins
- 19 Collins
- 20 Demel
- 33 Potts
- 04 Nolan
- 10 Collison Booked
- 23 Diarra (Noble - 73' )
- 26 J Cole (Taylor - 78' )
- 09 C Cole
- 12 Vaz Te (Jarvis - 61' )
- 30 Spiegel
- 02 Reid
- 27 Spence
- 07 Jarvis
- 14 Taylor
- 16 Noble
- 47 Lee
- 01 De Gea
- 02 Rafael
- 06 Evans
- 12 Smalling (Giggs - 78' )
- 15 Vidic Booked
- 28 Buttner
- 22 Scholes Booked (Valencia - 68' )
- 23 Cleverley
- 26 Kagawa
- 14 Hernandez (Van Persie - 68' )
- 19 Welbeck
- 13 Lindegaard
- 05 Ferdinand
- 07 Valencia
- 11 Giggs
- 18 Young
- 20 Van Persie
- 27 Macheda