Ronaldo opened the scoring on four minutes from the penalty spot.
Diego Costa levelled for Spain with a superb solo effort, but Ronaldo put his side back in front, as his shot was fumbled in by De Gea.
Costa equalized 10 minutes after the break and then Nacho fired the Spaniards in front for the first time in the game.
But with two minutes left on the clock, Ronaldo stepped up and spanked a free-kick into the top corner.
Shearer, however, questioned Ronaldo’s set piece accuracy at major tournaments and stressed that his second goal was due to De Gea’s error.
“One or two will ask why I said at half time that Ronaldo needs to work on free kicks,” Shearer told BBC Sport.
“Well, it’s his 45th attempt at major championships – and he’s done it today.
“His second goal was due to a very rare De Gea mistake. Ronaldo takes a gamble to his right, but it should have been a basic save.”
Ronaldo’s hat-trick against Fernando Hierro’s men was the 51st of his international career for his country.