Under-fire Spain had showed incredible character to come from 1-0 and 2-1 down to lead 3-2 in the Group B clash.
But Fernando Hierro’s men were pegged back right at the death when Ronaldo, who had already scored twice, fired home a trademark 88th minute free-kick to equalise.
It was so tough on the Spaniards, for whom Diego Costa had scored twice before Real Madrid defender Nacho put them ahead with a spectacular long-range effort.
There was also a howler to look back on from Manchester United keeper David de Gea but this match will go down in World Cup history for so many reasons.
This was always going to be one of the most eagerly-awaited and high profile ties of the group stages, but the drama of the last few days had elevated it to even greater importance. And it didn’t disappoint.
Spain, of course, went into the match with a new manager – the ex Bolton defender Fernando Hierro, who had been asked to step up from the role of director of football to lead the team in Sochi.
He got the call after predecessor Julen Lopetegui was unceremoniously sacked on the eve of the tournament for engineering himself a new job at Real Madrid – without telling the Spanish Football Federation.
The depth of the crisis cannot be underestimated, especially for Spanish Football President Luis Rubiales who has split opinion in Spain with his decision.
Rubiales sat in the stands at the Fisht Stadium in Sochi, nevertheless, for a Iberian derby that suddenly took on huge importance for his country’s unity.
Unfortunately it took just three minutes for the crisis to deepen.
Cristiano Ronaldo, a Real Madrid man who will have Lopetegui as his club manager next season, embarked on his first run down the left wing, produced a trademark step-over and tempted the careless Nacho into a stupid challenge.
Yes, Ronaldo left his leg in and, yes, Nacho tried to look as though he was pulling out. But he caught him all the same and referee Gianluca Rochhi had no choice.
There was never any doubt, either, over who would take the penalty or whether it would be scored – and Ronaldo fired it ruthlessly and perfectly into the right-hand corner.
It was exactly the start embattled Spain didn’t need. But it was also an historic moment for the Portuguese legend.
He is now the first player in history to score in eight consecutive major tournaments (including four World Cups).
Spain were rattled and although David Silva wasted a good chance minutes later, you could sense their stress.
But somehow, in a match played at a terrific pace, they pulled themselves back from the abyss with classic Diego Costa strike.
The former Chelsea man clobbered Pepe with a brutal aerial attack, got away with it and then scored a stunning individual goal as he twisted one way and then the next before slamming home from 20 yards. Spain were level – and in the ascendency.
In fact they almost went 2-1 up when Isco hit a thumping long-distance drive that cannoned back off the crossbar and landed plump on the goal-line with keeper Rui Patricio well beaten.
Portugal were always dangerous on the break, however. And out of nowhere they made it 2-1 after 44 minutes with a Ronaldo left-foot strike which Manchester United keeper De Gea embarrassingly fumbled into his own net.
What an error, and what a way to heap even more pressure on his side at a crucial moment.
Thankfully for de Gea, Costa got him out of trouble after 55 minutes.
David Silva’s cross from the left was headed back across goal by Sergio Busquets and Costa muscled his way to the ball first to finish from close range for 2-2.
Then, incredibly, Spain made it 3-2 from the most unlikely source.
Silva’s ball into the box was hurriedly cleared by Portugal but it fell to Real Madrid defender Nacho 30 yards out – and he belted it straight into the goal with the outside of his right foot.
Portugal (4-2-3-1): Patricio; Cedric, Pepe, Fonte, Guerreiro; Fernandes, Carvalho, S Silva, Moutinho, Ronaldo; Guedes.
Spain (4-2-3-1): De Gea; Nacho, Pique, Ramos, ; Coke, Busquets; D Silva, Isco, Iniesta; Costa.