It seemed certain to be another frustrating afternoon for the hosts, who were stifled by the Hammers’ organisation and came no closer than Fred’s second-half effort that was saved by Alphonse Areola.
But with less than 30 seconds of the three minutes of injury time remaining, United broke and in a move that involved all three substitutes, Edinson Cavani held his run to remain onside as he collected Anthony Martial’s short pass before rolling a cross to the far post, where it was converted by Rashford.
The result was harsh on the Hammers. In a game of few chances, Jarrod Bowen drove a shot into the side-netting before Tomas Soucek’s glancing header bounced just wide of the far post with four minutes remaining.
But Rashford had the final word as United secured back-to-back wins for the first time under Ralf Rangnick.
The result takes United into the top four for the first time in three months, with the Hammers dropping down to fifth, although Tottenham and Arsenal could overtake them if they win their games on Sunday.
United’s season stabilised
Such has been the difficulty of United’s season, entering the rare January international break on the back of one defeat in 13 games since Ole Gunnar Solskjaer’s dismissal on 21 November has to be seen as relative success.
There are still numerous problems for Rangnick to address, most immediately the futures of Martial, who was greeted with boos and cheers as he was introduced for the first time since Rangnick’s arrival amid interest from Sevilla and his well-publicised desire to leave, and Jesse Lingard before the transfer window closes on 31 January.
A season spiralling out of control has been stabilised to an extent but this latest effort was unconvincing and another of those days when Cristiano Ronaldo failed to live up to his superstar billing.
The neck injury Rangnick revealed Ronaldo was suffering from in the build-up to the game eased sufficiently to allow the 36-year-old to start but there was little in his performance to suggest he was happy with his situation.
An elaborate tee-up to a 25-yard free-kick only produced a shot straight into the wall and then he moaned at Mason Greenwood for not crossing the rebound into an area he had ventured into rather than shooting, which is what the youngster did.
Passes went astray too frequently and a penalty claim was waved away by referee Jon Moss.
Ronaldo was still shaking his head minutes later but TV replays showed Kurt Zouma made little meaningful contact with the United forward, certainly not enough to send him flying in the box.
There was more elaborate complaining after half-time when he was penalised for a high kick on Craig Dawson, whose head, Ronaldo felt, was too low.
Rangnick stuck with the veteran though. And, with the rest of his team-mates, he was celebrating at the final whistle.
Of England’s Euro 2020 heroes from last summer, none has kicked on in their club careers the way Declan Rice has.
West Ham fans will hate it and, as Moyes points out, the 23-year-old has a contract that runs to 2024. But Rice is hot property.
When he strode from the tunnel first before kick-off, it was impossible not to think he might be doing that walk on a more regular basis in future.
His screening of the Hammers’ defence was immaculate and the way he nipped in to dispossess Ronaldo, before racing away from his opponent as he tried to win the ball back, had a touch of impudence and authority in equal measure.
As Moyes’ awful personal run of away games without a win at ‘big six’ teams extends to 45, Rice will know many of those clubs would take him right now.
Even with a European campaign to look forward to in the second half of the season, West Ham know keeping their skipper will be the biggest task of the summer.
Manchester United’s next game is in the FA Cup, against Middlesbrough at Old Trafford, on Friday, 4 February (20:00 GMT). West Ham are in FA Cup action the following day, at non-league Kidderminster (12:30 GMT).