The Real Madrid superstar crashed in an 88th-minute free-kick to earn a point for the European champions in this Group B opener, after a second-half goal from Nacho had put the Spaniards 3-2 ahead.
Before that, Ronaldo had twice given his side the lead in the first half, only for Diego Costa to equalise each time for a Spanish side who peformed admirably on a steamy night on Russia's Black Sea coast after a chaotic few days.
Fernando Hierro was making his debut on their bench, just two days after the sensational sacking of Julen Lopetegui, but Ronaldo stole the headlines.
After only three goals in total at the last three World Cups, he doubled his tournament tally in one night here, and has now scored at eight consecutive major tournaments going back to Euro 2004, when he was still a teenager.
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.
"It's a nice personal record to have, one more in my career," said Ronaldo, before adding: "For me the most important thing is to emphasise what the team did against one of the favourites to win this World Cup."
His hat-trick came just hours after legal sources in Spain said Ronaldo had agreed to pay the Spanish taxman 18.8 million euros ($20 million) to settle a tax fraud claim.
But Ronaldo was clearly not distracted by that, and his team-mate Bernardo Silva admitted after the game that "when he plays like that, everything is possible."
Ronaldo had put Portugal ahead from a fourth-minute penalty after going down in the box under a foul from his Real club colleague Nacho, playing at right-back with Dani Carvajal not fit.
Hierro, who cut an animated figure as he stood on the touchline with his sleeves rolled up, must have wondered at that point what he had let himself in for. Yet Spain responded superbly.
"We have to be very proud of the boys. To lift ourselves in adversity and turn the match around, we showed character, pride," said Hierro, himself a former Spain star but someone with limited coaching experience.
"This is a mature team. They have been playing together a long time and it is a pleasure to have these players."
The 2010 World Cup winners drew level for the first time in the 24th minute via a trademark piece of centre-forward play by Costa, who left Pepe on the floor as the pair challenged for a high ball, before breaking into the box and planting a low shot into the bottom corner.
Portugal appealed in vain for a foul on Pepe, but there was no intervention from the Video Assistant Referee.
The European champions went back in front just before the break in what was a horrible moment for Spain goalkeeper David De Gea, who made a complete hash of dealing with Ronaldo's shot from 20 yards that was well struck but straight at him.
But Spain regrouped at the interval and drew level 10 minutes into the second half with a textbook set-piece counter, Sergio Busquets heading a free-kick back across goal for Costa to turn it in.
Three minutes after that, Nacho's glorious effort from 22 yards made it 3-2, his half-volley curling into the net off the left-hand post.
That looked to be that, before Ronaldo intervened to have the last word, and Morocco -- beaten 1-0 by Iran earlier on Friday -- will not look forward to facing him in their next game.
"When you come up against a player like Cristiano these things can happen. Whoever has him on their side is lucky," added Hierro.