Wayne Rooney scored and then missed a penalty on his return from injury as Manchester United reached the FA Cup fourth round at West Ham's expense.
The England striker, making his first appearance since Christmas, slid home from close in to put the hosts ahead.
West Ham were denied a penalty when the ball appeared to strike Rafael's arm in the penalty area.
But on a night of mixed fortunes, Rooney blasted a late penalty over to set up a tense finish at Old Trafford.
Matt Taylor went close for West Ham, but the home side stood firm to set up a home tie with Fulham on 26 or 27 January.
Having helped keep United in the tie at Upton Park with a delightful half-volleyed pass that set Robin van Persie on his way, Ryan Giggs once again stood out from the rest.
Sharper to the ball and swifter to use it, the Welshman delivered a midfield master-class, allying energy that belied his years to pace and purpose.
However, it was another night of frustration for Sam Allardyce's side. West Ham had been the better side in the first game only for Van Persie's sublime late goal to earn the Red Devils a reprieve. Once again, they had opportunities at Old Trafford but the chances and the tie slipped away.
Sir Alex Ferguson is not known for handing out second chances and for much of the first half his side dictated the tempo and toyed with their opponents. But even with Rooney and Anderson back after injury, Old Trafford felt subdued, perhaps expectant.
There was a sense that having come within minutes of a being knocked out of the FA Cup in the first leg, the Premier League leaders would not make the same mistake twice.
Ferguson's side made a dream start, snatching the lead through Rooney inside ten minutes.
The goal was as simple as it was effective. Anderson, making his first start since hobbling out of the 4-3 win over Reading on December 1, opened up the West Ham defence with a through ball that skidded into Javier Hernandez's path. The Mexican beat the offside trap, squared the ball to Rooney who slid the ball into an empty net.
Rooney pointed to the sky as he ran away to celebrate in memory of his late sister-in-law.
The Red Devils might have had a second after 28 minutes, as Giggs combined with Antonio Valencia to tee Nani up for a fizzing volley that was cleared off the line by the young West Ham defender Dan Potts.
It was too easy for Ferguson's side - the pace dropped, along with the temperature, and passes went astray. The visitors grew in confidence and in two spells either side of half time, West Ham seized the initiative.
Taylor twice went close in the space of two minutes, misplacing his pass when well-placed before firing over from 12 yards.
Sensing an opportunity, Allardyce threw Kevin Nolan and Jack Collison into the mix. The former Bolton and Newcastle midfielder almost made an immediate impact, only to see his shot blocked by Chris Smalling.
As West Ham pushed for an equaliser, United broke once more.
Another surging run by Giggs ended with his clipped cross striking the outstretched arm of Jordan Spence, prompting referee Phil Dowd to award a penalty.
Rooney, however, could only blast his spot-kick high over Jussi Jaaskelainen's crossbar.
Manchester United boss Sir Alex Ferguson on his team's record of five penalties scored and four missed this season: "I think we have to improve at that.
"There have been several great examples over the years -[(former Southampton midfielder] Matthew Le Tissier scoring 47 out of 48.
"A penalty kick is your opportunity to take advantage of a foul or a handball or whatever and score a goal."