Spain led with three minutes to go after Nacho Fernandez hit a wonderful 25-yard drive but Ronaldo was determined to steal the headlines for himself.
And he ended the day with a World Cup match-ball after hitting an outrageous late free-kick to ensure the spoils were shared in this blockbuster clash in Sochi.
Captain Ronaldo had given Portugal a fourth-minute lead from the penalty spot after he was fouled by Madrid team-mate Nacho, restoring the lead thanks to David de Gea's horrible mistake.
Diego Costa replied twice to get the 2010 champions level, with Nacho's beautiful goal having seemingly settled a high-class encounter at the Fisht Stadium.
Ronaldo, though, had other ideas and stepped up to beat De Gea again with a perfect 20-yard free-kick, almost snatching all three points with a stoppage-time header.
45 - Cristiano Ronaldo's free-kick was the first that he has scored from a direct free-kick in a finals tournament, from what was his 45th attempt (World Cup & Euros combined). Moment. #PORESP #POR #ESP #WorldCup pic.twitter.com/hKzeGfa0Yl
— OptaJoe (@OptaJoe) June 15, 2018
Friday's earlier games were both settled by late winners but Ronaldo was immediately in the thick of the action, tumbling under a rash challenge from Nacho, who was deputising for Dani Carvajal, another Real Madrid team-mate.
Although De Gea attempted to distract Ronaldo before the former Manchester United man took the spot-kick, he sent the goalkeeper the wrong way to make yet more history, becoming the first player to score in eight consecutive international tournaments.
David Silva smashed a shot over the crossbar as Spain - who sacked coach Julen Lopetegui on the eve of the tournament and replaced him with Fernando Hierro - tried to find an immediate response, the Manchester City midfielder then having an effort deflected wide after magical footwork from Andres Iniesta.
An increasingly dominant Spain did draw level in the 24th minute, though, with a goal that survived a VAR review.
Costa bullied Pepe in the air, then twisted and turned away from two Portugal defenders to rifle home his seventh goal in 11 international appearances.
— OptaJoe (@OptaJoe) June 15, 2018
Technology was soon called into action again when Isco's rocket thumped against the crossbar, but replays showed the ball bounced on the line before Portugal smuggled it away.
De Gea made a terrible error in a warm-up friendly against Switzerland and he was guilty again with a horrible moment that handed Portugal back the lead on the stroke of half-time.
Portugal had not recorded a shot on target since Ronaldo's opener but, when the forward collected possession on the edge of the area and drilled a low left-footed drive at De Gea, the goalkeeper somehow allowed the ball to slip through his grasp.
Spain did not allow that mistake to distract them, though, Costa levelling the scores in the 55th minute.
Silva's free-kick to the back post was headed back across goal by Sergio Busquets, with Costa timing his run into the box to nudge home.
Within three minutes Spain were in front for the first time, thanks to Nacho's spectacular 25-yard goal.
A Portugal clearance rebounded kindly to the Madrid defender, who hit a first-time drive that curled beautifully out of Rui Patricio's reach, via a double bounce off the woodwork.
— FIFA World Cup (@FIFAWorldCup) June 15, 2018
Substitute Ricardo Quaresma fired a warning shot over the crossbar but there was only one man who was going to step up for Portugal.
Ronaldo was fouled on the edge of the penalty area and he could hardly have placed the ball in a more ideal position for one of his special set-pieces, despite having failed to score with 44 previous free-kick efforts in World Cups and European Championships.
With the Sochi crowd on the edge of their seats, Ronaldo delivered with a trademark curler that bent over and away from the wall to settle a contest that will go down in history as a World Cup classic.
Photo Getty Images. Caption: Real Madrid and Portugal star Cristiano Ronaldo