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.