De Gea was badly at fault for Ronaldo's second goal, letting a 20-yard shot go straight through his body and into the net, after the Manchester United goalkeeper had also made a similar error in a warm-up friendly last week.
Spain and Portugal clash on Friday, June 15, in an early highlight of the World Cup in Russian Federation as the Spanish camp insists the players are united despite this week's extraordinary sacking of coach Julen Lopetegui.
The game was played in Russia's Black Sea resort city of Sochi on Friday.
Outside favourites of the tournament, Portugal will kickstart their FIFA World Cup campaign with a titanic battle against Spain, on Friday.
The match got off to an explosive start when Ronaldo beat Nacho on the left of the box with a stepover, was tripped and emphatically converted the penalty himself.
Aspas tested Patricio soon after being introduced, but it was at the other end of the field where the late drama would come as Ronaldo sent a free kick dipping over the Spain wall, completing the 51st hat-trick in World Cup finals history and the 51st hat-trick of his senior career.
Where to begin? From Costa nabbing his first and second-ever World Cup goals to Nacho scoring his first for Spain with a blockbuster strike. Of course it all looks a lot better when you put the ball in the top corner, as he did, giving de Gea no chance this time.
He is just the fourth player to score at four World Cups, following in the footsteps of Pele and German duo Uwe Seeler and Miroslav Klose. "We must focus on Iran", he said.
Ronaldo's records might stack up like his goals, but he was determined to focus on the team ethos of the reigning European champions. And a defender poked the ball free before Guedes could get off a shot.
Portugal loudly complained Costa had fouled Pepe, and replays showed there was contact by the Spaniard's arm with Pepe's body. "We've come back and equalized twice, we feel great commitment and pride".
De Gea added: "The example of Diego Costa is clear in my mind".
Spain: De Gea; Odriozola, Pique, Ramos, Alba; Alcantara, Busquets, Iniesta; Isco, Costa, Silva. Portugal has possessed the ball for just 32 percent of the game but have connected on both of its shot attempts on goal.
Spain topped their group, dropping just two points in qualifying, remaining unbeaten.
Portugal: The team has been able to succeed recently because of its steady defense, but this time it was not able to hold on to its early leads despite twice getting ahead with goals by Ronaldo.
'The good thing with the best is that in the next match he will be there - not afraid, confident to go & ready to help his team.
It was typical of the now 33-year-old to take the headlines after news from the Spain camp had dominated the build-up to this game.
- The 2026 World Cup will be played in North America
- Comcast eyes Fox after AT&T gets Time Warner merger approval
- Queen and Meghan, Duchess of Sussex open Mersey Gateway bridge in Widnes
- Meghan Markle Wears Givenchy on Royal Visit to Cheshire
- Trump says his agreement with North Korea will be good for China
- Trump's 'appalling' Kim summit slammed by rights advocate
- Afghanistan not nervous ahead of realising test dream - Stanikzai
- How do North Korean defectors feel about the Trump-Kim summit?
- Trump in surprise summit move says he will halt Korea war games
- North Korea sanctions to stay until full denuclearisation, says US