United appeared certain to open the door for Arsenal and Chelsea when their defence went into meltdown, gifting the Hammers two first-half penalties which Mark Noble duly dispatched.
But the leaders were rewarded for going for broke in the second half, Rooney starting the fightback with just 25 minutes remaining, completing his 14-minute treble from the spot before substitute Javier Hernandez sealed the points.
The result moved United eight points clear ahead of Arsenal and Chelsea before their respective games, while dragging West Ham back into the drop zone on goal difference.
Old Trafford boss Sir Alex Ferguson spent the build-up to today's game bemoaning refereeing decisions he claimed had gone against his side this season.
But United got the rub of the green today, with returning captain Nemanja Vidic lucky to stay on the field when it was still 2-0.
United went into the game having won only four away league games this season and were facing a Hammers side who had won their last three home games in all competitions.
They also thrashed United 4-0 in the Carling Cup in November but that was against a weakened side.
And the visitors showed they were more serious about today's game in the fourth minute when Robert Green was forced to tip over Chris Smalling's header from Ryan Giggs' fourth-minute corner.
United were dominant but fell behind in dramatic fashion in the 10th minute when a long ball from Thomas Hitzlsperger cleared the entire defence to put Carlton Cole clean through.
The striker hesitated and Patrice Evra looked to have recovered but the full-back inexplicably handled the ball and Lee Mason rightly pointed to the spot.
Noble sent Tomasz Kuszczak - in for the injured Edwin van der Sar - the wrong way and Upton Park erupted, but West Ham were immediately on the back foot again, giving United far too much time and space out wide.
A desperate clearance from Manuel da Costa denied Giggs but the Hammers settled and United pressed the self-destruct button again in the 24th minute.
Cole teased Vidic on the edge of the box and the Serbian took the bait, tripping the forward for an obvious foul.
It was tight as to whether the offence took place outside the box but Mason had no doubt and Noble blasted penalty number two into the roof of the net.
The bizarre pattern of the game continued and United looked certain to pull one back just past the half hour, the fit-again Park Ji-sung blasting a left-foot drive too close to Robert Green, who nevertheless pulled off a superb reaction save.
The visitors' frustration boiled over when Darron Gibson was booked for kicking out at Noble.
Hitzlsperger blasted a difficult volley from Gary O'Neils' cross wide and although the visitors ended the half stronger, Vidic pressed the self-destruct button again when he hauled down Demba Ba three minutes from the break.
The United captain was last man but was spared a red card, with Mason controversially appearing to decide Ba would not have retrieved the loose ball.
Ferguson threw on Hernandez for Evra after the interval, moving Giggs to left-back.
The substitute almost made an instant impression when his improvised flick from Giggs' cross sailed over.
Vidic could easily have earned a second yellow card after tangling again with Ba.
Rooney, who had orchestrated United's good play in the first half began to look lost.
His hesitation soon got him a hefty kick on the ankle from Da Costa, who was rightly yellow carded.
United went for broke in the 64th minute when Dimitar Berbatov replaced Park as they were awarded a free-kick, which saw them finally get back in the game as Rooney curled home from 25 yards.
Cole was replaced by Frederic Piquionne before Green saved from Berbatov from the tightest of angles.
Rooney came to the rescue again when Antonio Valencia's ball found him on the edge of the box and West Ham's defence allowed him to take a touch and fire low across Green.
United were rampant and were awarded a penalty of their own for handball with 12 minutes remaining.
Fabio's skill left Matthew Upson on the deck and when the defender got back up, the full-back kicked the ball against his arm.
While the Hammers opposed the decision Rooney stepped up to complete the most unlikely of hat-tricks.
Gibson should have made it 4-2 before West Ham threw on Victor Obinna and Robbie Keane for O'Neil and Noble.
Smalling survived another handball shout before Hernandez pounced on a piece of terrible defending six minutes from time to turn in Giggs' cross.
Rooney was withdrawn for Nani as United comfortably saw out their latest fightback.