The Mexican substitute’s winning goal capped a strong late flourish from United, who had equalised only two minutes earlier through the ever-dependable Wayne Rooney.
But even in victory, and even with a fight back reminiscent of former manager Alex Ferguson’s glory years, United looked far from their championship-winning form of last season.
Robin van Persie marked his 50th start for the club with his 38th goal, cancelling out a Peter Crouch opener, only for Marko Arnautovic to restore Stoke’s lead just before the interval.
Hernandez, a second-half substitute, struck 10 minutes from time to bring United three sorely-needed points, heading in Patrice Evra’s left-wing cross from five yards and sparking touchline celebrations from Moyes and coach Phil Neville.
United had started the game with an apparent spring in their step after a midweek success over Real Sociedad in the Champions League, but they succumbed to the very first Stoke attack after three minutes when full-back Erik Pieters was allowed far too much space down the left.
His superb cross found Crouch, who extended his lengthy frame to turn a shot goalwards that was well saved by David de Gea, only for defender Jonny Evans to play the rebound against the Stoke forward and back into the United goal.
There may have been a slice of fortune in the manner of the finish, but Stoke would go on to show they deserved it over the remainder of the first half, with Crouch volleying narrowly over and Jonathan Walters’ close-range shot being saved by United goalkeeper De Gea.
The visitors were growing in confidence, their hosts struggling to break down their dogged defending and looking short on attacking ideas, although Rooney, at least, was performing at near his peak.
His 25-yard shot after 32 minutes finally brought a save out of Asmir Begovic, the Stoke goalkeeper turning his effort over the bar one-handed.
Van Persie’s equaliser came in the 43rd minute, carved out on the right by Nani, whose cross reached Rooney for a powerful header.
Begovic did well to turn the ball away, but only as far as Van Persie, who drove the rebound home from eight yards for his ninth goal in his last seven appearances against Stoke.
That should have been a platform for United to build upon, but in the final minute of the half Phil Jones brought Arnautovic down on the corner of the home team’s area and presented the Austrian with a free-kick.
The Stoke forward conjured up a superb shot that hit the underside of the United bar and crept over the line as De Gea collapsed vainly into the net.
United’s frustration was obvious and referee Lee Mason had to separate Van Persie from defender Ryan Shawcross as tempers flared.
Soon after the restart, Rooney’s near-post shot was well covered by Shawcross but, before the hour had elapsed, Moyes had seen enough, throwing on teenage winger Adnan Januzaj in place of Nani, in a switch that was wildly popular with the home supporters.
Eventually, it required a rare defensive error from the visitors to allow United a route back into the game from Van Persie’s 78th-minute corner.
Rooney, having slipped away from his marker, did the rest with a well-judged glancing header into the top-left corner to make it 2-2, before Hernandez applied the coup de grace.