Solskjaer's men were staring down the barrel of another embarrassing group stage exit from the Champions League after deservedly falling behind early in the second half to Paco Alcacer's smart finish.
Alex Telles' stunning strike quickly levelled, but they looked set to drop more points in Group F until Ronaldo's late intervention.
Despite the result, there was little in the performance to quell the growing questions as to whether Solskjaer is the man to get the best out of a squad of supremely talented individuals that are yet to click as a collective.
"That's what happens at Old Trafford, we had to throw caution to the wind and got lucky in the end," said Solskjaer.
"When you've got Cristiano on the pitch there is always a chance."
Ronaldo's late show beat Solskjaer's famous strike to win the Champions League in 1999 as United's latest winning goal in the competition.
However, for most of the 95 minutes Villarreal were the better side and were left to rue not taking their chances as they sit bottom of the group on one point from two games.
"We're annoyed. The game was basically over, we just needed to see it out and we didn't," said Villarreal defender Pau Torres. "We were impeccable before that. We took the lead, were creating chance and were better than Man United at Old Trafford."
United were without three of their first-choice back four with Harry Maguire and Luke Shaw sidelined by injury, while Aaron Wan-Bissaka was suspended after being sent off in the 2-1 defeat to Young Boys on match day one.
A makeshift defence looked as such in the first half as Villarreal wasted a host of chances to inflict more misery on the Red Devils after beating them in May to win the Europa League.
De Gea was the fall guy in the Europa League final as he was the only player of the 22 on both sides to fail to score in a marathon penalty shootout.
However, he has started the season in supreme form and made brilliant saves from Arnaut Danjuma and Alcacer to keep the game scoreless at half-time.
United fall behind
United did not heed their warnings as eight minutes into the second period another promising break from Danjuma finally got the finish it deserved as Alcacer prodded through the legs of De Gea at the near post.
Telles was at fault for the opening goal as he played Danjuma onside.
But the Brazilian quickly made amends in spectacular fashion as he volleyed home Fernandes' free-kick from outside the area for his first United goal.
Solskjaer had named an extremely offensive line-up with Ronaldo flanked by Jadon Sancho and Mason Greenwood, and Paul Pogba alongside Fernandes in midfield.
But it was another night to forget Sancho since his £73 million move from Borussia Dortmund in July.
The England winger was easily kept in check by Juan Foyth before being replaced 15 minutes from time by Edinson Cavani.
The Uruguayan had a golden chance to instantly make himself the hero, but somehow headed wide with the goal gaping from Greenwood's perfect cross.
De Gea saved United once more five minutes from time in a goalmouth scramble to deny Moi Gomez and Boulaye Dia.
And Villarreal's profligacy in front of goal came back to haunt them as the all-time top goalscorer in Champions League history showed them how to finish.
Jesse Lingard turned a loose ball Ronaldo's way deep into stoppage time and his effort had too much power for Rulli.