A Patrice Evra handball and Nemanja Vidic foul on Carlton Cole allowed Mark Noble to twice score from the spot for the relegation-battling Hammers.
Vidic escaped a red card for a foul on Demba Ba before Rooney curled in a free-kick and powered in a shot.
A Rooney penalty put the visitors ahead and Javier Hernandez poked in a fourth.
West Ham will point to the decision not to send off Vidic and Rooney's penalty being awarded courtesy of a harsh handball against Matthew Upson as key decisions against them.
The visitors, on the other hand, again showed the resilience and resolve that will let their title rivals know they will not be knocked off the top of the league without a battle.
With depleted resources and under challenging circumstances, Sir Alex Ferguson's side proved that although they might not have the flamboyance of United sides of the past they make up for it with their fighting qualities.
Upton Park has proved the scene of some difficult memories for the Red Devils, who had been limited to six wins at the east London ground in their last 17 visits before the game.
Most recently, United had their unbeaten start to the season ended by an emphatic 4-0 loss in the Carling Cup at West Ham in November and, along with a revitalised home side breathing new life into their attempts to beat the drop, the visitors had cause to be wary.
Injuries, suspensions and with half an eye on their Champions League last-eight tie at Chelsea on Wednesday only increased the size of a task United ultimately passed, despite the scare provided by the Hammers.
Ferguson, watching from the stands as he served the second of a five-match touchline ban, had opted to start with a 4-5-1 formation.
The attacking threat of Nani, Dimitar Berbatov and Hernandez had been left on the bench and, despite a promising opening, United's afternoon quickly began to disintegrate.
West Ham launched a counter-attack with Thomas Hitzlsperger's long ball out of defence releasing striker Cole and he earned a penalty when an attempted chip over left-back Evra was handled by the defender.
Noble stepped up to confidently send keeper Tomasz Kusczsak the wrong way with the resultant penalty before another Hammers break gave him another chance to score from the spot.
This time Cole's nifty footwork deceived Vidic, who tripped the striker before suggesting that the offence took place marginally outside of the area.
Referee Lee Mason disagreed as he awarded another penalty for the home side which Noble again unerringly sent in as he went for power rather than placement.
The visitors had seen plenty of the ball as they were caught out by two counter-attacks but found their probing nullified by a determined West Ham defence.
When the Red Devils did get a sight of goal keeper Robert Green responded by palming a ferocious Park Ji-Sung shot over his goal.
Manchester United's defence was looking shaky and, when Vidic hauled down Ba to deny the Hammers forward what might have been a clear goalscoring opportunity, the Red Devils centre-back escaped with a yellow card just before half-time.
The Premier League leaders were stumbling but, having salvaged a draw at Aston Villa and win at Blackpool from similar positions, they are a side you cannot write off and so it proved.
Ferguson brought Hernandez on at the break before Berbatov also came of the bench as his side manufactured another comeback as they dominated the second half and were rewarded through the finishing prowess of Rooney.
The England striker brilliantly curled in a 25-yard free-kick before he controlled a pass, which took two defenders out of the game, and powered a drive past the despairing dive of Green.
Upson's handball from a Fabio Da Silva cross gave Rooney the opportunity to slot in a penalty for a 14-minute hat-trick as the Hammers, who would have at-least temporarily moved 13th with victory, capitulated to ensure they would close the day in the bottom three.
Hernandez also got in on the scoring for Ferguson's side as they completed only a fifth away win in 16 league games this season.