Mark Hughes' visitors had made a mockery of their paltry goalscoring record so far this season by taking a third-minute lead through Peter Crouch and going straight back in front through a Marko Arnautovic free-kick after Robin van Persie had equalised for the home side.
But Moyes' substitutions paid off with Hernandez providing the inspiration for United when he headed home Patrice Evra's cross just two minutes after Rooney had flicked his side back level.
Moyes said: "I thought with 15 to 20 minutes to go the supporters were terrific - they drove the team on and they played a big part in getting the result.
"I thought in the end we had to go for it. I thought we did a lot of good things but an awful lot of really poor things that put us in the situation we were in.
"We got ourselves back in the game just before half-time only to concede from a poor, poor free-kick.
"That got us going in at half-time on a downer but I said at half-time your job is to win the game and you're more than capable of doing it. We needed the substitutes and they made a big difference."
Moyes' relief was evident after a tumultuous first period in which the visitors attacked with strength and purpose and ought to have extended their lead, Crouch spooning over the bar and Jonathan Walters bringing a brilliant save out of David De Gea.
Moyes added: "We needed our goalkeeper to make an extraordinary save again in the first half but that's what he's in the team for.
"At times our play was good but we just couldn't find the final ball. But the three centre forwards we had on the pitch scored a goal and that was pleasing."
Disappointed Stoke boss Hughes believes his side deserved to hang on for at least a point after an heroic effort to end a winless run at Old Trafford stretching back to 1976.
Hughes said: "I do think it was unjust, in terms of what we produced, the effort we put in and the chances we created.
"I certainly felt in the first half we could have been three or 4-1 to the good in terms of chances created. I didn't think United created much apart from the key moments that took the game away from us.
"We're really disappointed given the level of performance we produced. We had a game plan which needed commitment, it needed people to be brave and do the hard yards that affected the game, and that's what we did.
"I thought my players were excellent, they took the game to United and really shook them."
- Sports & Recreation
- Peter Crouch
- Wayne Rooney