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.
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.
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.