The Premier League champions were once again out of sorts on their own turf and looked to be heading for defeat as a Peter Crouch effort and a sublime Marko Arnautovic free-kick sandwiched Robin van Persie's equaliser.
However, Wayne Rooney levelled the scores in the 78th minute before substitute Hernandez netted a dramatic winner two minutes later.
David Moyes' men looked to be heading for a third straight home match without victory in the Premier League, in another out-of-sorts performance at Old Trafford. Crouch toe-poked Stoke ahead before Van Persie fired home a rebound from Rooney's header.
Arnautovic's free-kick appeared to have handed Stoke the three points, but headers from Rooney and Hernandez in the closing stages ensured the visitors are still looking for their first Premier League victory over United.
Van Persie returned from a toe injury that kept him out United's 1-0 victory over Real Sociedad on Wednesday, while former United striker Mark Hughes brought in Crouch to lead Stoke's attack.
Stoke exploited United's recent home frailties right from the off and were rewarded with the opener in just the fourth minute. Erik Pieters burst through three challenges before crossing from the left and Crouch's initial shot was saved at point-blank range from David de Gea before Jonny Evans' attempted clearance rebounded off the striker and into the net.
Moyes' men were wasteful in possession and were nearly punished further when Crouch hit a first-time volley at full stretch that narrowly cleared the crossbar.
Stoke came even closer when Jonathan Walters hit a half-volley from 12 yards and drew a smart save from De Gea.
The United faithful were becoming restless, but the home side gave them something to cheer about with an equaliser three minutes before the break. Rooney's back-post header was well saved by Asmir Begovic and Van Persie was on hand to fire in the rebound.
However, Stoke immediately restored their lead when Arnautovic curled a sublime free-kick from the left that hit the bar and bounced into the goal with De Gea scrambling to attempt to make the save.
United upped the intensity after the break but only had blocked efforts from Rooney and Van Persie to show for their efforts.
Defensive confusion nearly led to Walters breaking clear in the 64th minute, but De Gea sprinted 40 yards off his line to make a vital interception.
Rooney restored parity in the 78th minute when he lost his marker to head home from Van Persie's corner.
And the home fans were once again on their feet with 10 minutes remaining when good work from Patrice Evra on the left led to the Frenchman hanging up a cross and Hernandez adding the header from six yards.
The win is just United's second in the league this season, while Stoke's winless run in the top flight extended to six matches.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.