Two goals from Villa striker Andreas Weimann put the home side in control early in the second period.
But Hernandez, a half-time replacement for Ashley Young, scored twice and saw his shot deflect off Villa skipper Ron Vlaar for the other United goal.
Victory stretched the Red Devils' advantage at the top of the Premier League to four points over Chelsea, who entertain Liverpool on Sunday.
The only downside for United was an ankle knock suffered by Wayne Rooney which could place a question mark over him being fit for England's friendly with Sweden in Stockholm on Wednesday.
Ferguson said: "It reminded us of a cup game here a few years ago when we were 2-0 down. I think Van Nistelrooy scored a couple and we won 3-2.
"We were disappointed with the first-half performance, it has to be said.
"You had to give credit to Aston Villa, they never gave us a minute's peace on the ball.
"When they got the second goal we were up against it, but once we scored our first goal, you always felt they were going to do it."
Hernandez has now netted seven times in the last five games.
Ferguson said: "I've been saying it for weeks, that he's such a great professional.
"He doesn't complain. We do prefer that one striker with one playing behind.
"It didn't work today in the first half but when Javier came on and Robin dropped a bit deeper, and Wayne went out to the left-hand side, you had a feeling that if we got a goal we would go on and win it."
Ferguson added: "The tenacity of our performance in the second half was really brilliant.
"I think the evidence of the second half is we never give in. We can come from behind against anyone as we've done eight times this season, and that is encouraging in that respect.
"Anyone who plays against us knows they have to play to the 95th minute."
As regards Rooney's second-half ankle setback, Ferguson said: "He's got an ankle knock and he has ice on it. We'll see how he is tomorrow."
Villa boss Paul Lambert had nothing but praise for his side despite United's fine comeback.
Lambert said: "I am proud. I thought they were outstanding. I couldn't ask for any more. But that's why Manchester United are a top side. They do it week in, week out.
"I am really proud with what they have given me. I think we have been playing well for a couple of weeks, and hopefully the confidence will be there in abundance after that.
"The Premier League is really tough. They are a young side but they are playing really well at the minute.
"They kept on going. I couldn't fault them for the way the lads played and kept going. The crowd are your gauge. I am absolutely gutted to lose because they gave me everything they had."
Lambert praised the finishing power of Weimann, whose two goals had put Villa in command before the United revival.
He said: "One thing Andreas is that he's a natural finisher. He's a young lad. He seems to have been around for years. The future is very good.
"The front three are a handful. They are three young lads, but it bodes well for the future."