Premier League: Aston Villa 2 Manchester United 3
The Mexican scored twice and played a significant part in another as United moved four points clear atop the English Premier League with the win at Villa Park.
Andreas Weimann completed sweeping counter-attacking moves either side of half-time to send Paul Lambert's side into a shock two-goal lead.
But Hernandez, who had replaced Ashley Young at the break, made all the difference.
He pulled United back into the game after 58 minutes before another of his shots deflected off Ron Vlaar for the equaliser.
And the clinical forward finally made United's pressure pay when he headed home Robin van Persie's free-kick in the 87th minute.
For most of the first half, statistics showed United were dominating possession but Villa, led by Vlaar in central defence, continued to stand up to the test and the visitors' frustration grew.
On the stroke of half-time, Lambert's team made their excellent resistance count.
Gabriel Agbonlahor initiated a break down the left that was continued by Christian Benteke.
Benteke showed tremendous pace and power to shake off the challenge of Chris Smalling before rolling the ball into the path of Weimann, who side-footed a powerful effort into the roof of the net from the edge of the area.
A misplaced Paul Scholes pass led to another Villa break for their second goal as a dummy from Benteke created space for Agbonlahor on the left.
Agbonlahor whipped in a powerful low cross for Weimann, who had timed his run to perfection and tapped in to make it 2-0.
Scholes went some way to making amends by playing the pass that brought United back into the game just before the hour-mark.
Hernandez did superbly to control the midfielder's chipped ball and shake off Ciaran Clark before steering a low finish through the legs of Brad Guzan.
Within five minutes, United were level.
Agbonlahor failed to track the run of Rafael on the right flank and when the Brazilian crossed to the far post, Hernandez was on hand to pounce with the help of a big deflection off Vlaar.
Weimann almost had a hat-trick when he was denied by David de Gea from close range.
Van Persie struck the crossbar twice but provided the set-piece for the winner as Hernandez headed into the bottom corner to complete a remarkable comeback.