Cristiano Ronaldo produced one of the great World Cup performances as his dramatic late free-kick earned Portugal a draw with Spain in a classic encounter in Sochi.

The Real Madrid forward's 88th-minute swerving set-piece soared into the top corner to deny the Spanish a much-needed victory at the end of what has been a painful week for them in the south of Russia.

Their build-up had been dominated by the shock departure of Julen Lopetegui as boss two days before the tournament started but by the final whistle at the Fisht Olympic Stadium there was only one name on everyone's lips.

Ronaldo. Who else?

He had got the opener, too, a penalty in the fourth minute after Nacho felled him in the box, before Diego Costa's bullying low finish dragged Spain back into the match when they were at their most vulnerable.

But just before the break David de Gea made a terrible and uncharacteristic error, fumbling a zipping Ronaldo shot through his gloves and over the line. Another dose of adversity for Spain to deal with.

Lopetegui's hasty replacement, Fernando Hierro, saw his team respond through Costa again, the Atletico Madrid striker smashing in from Sergio Busquets' knockdown nine minutes after half-time, before Nacho redeemed himself with a stunning volley from the edge of the area that crashed in off both posts and seemed to have given Spain victory.

But, as so often, Ronaldo would have the last word.

Portugal's captain had spent large parts of the second half as a spectator, powerless to halt Spain's recovery, but he emerged from the shadows of this fascinating spectacle to define the game's result and in doing so become just the fourth player to score at four World Cups.

It was a titanic performance, a one-man show from one of the world's best, on the biggest stage of all.

Ronaldo into the record books (again)

Ronaldo was, well, Ronaldo. The star attraction for many of the thousands of fans from all over the world who gathered in Sochi did not disappoint.

At 33, you feel this is his last chance to win football's biggest prize - though his manager said afterwards that "he could once again score in a World Cup in Qatar" in four years' time - and he looks ready to drag his side along as far as he can.

He tasted glory at last with his national team at Euro 2016 but was forced off in the final. The way he galvanised those around him here makes you wonder whether Portugal should be considered serious favourites for this tournament, too.

Before this match Ronaldo had scored only three times from 13 World Cup games. His return still doesn't make for Ronaldo-like reading - six in 14 - but with the opening goal he became the fourth player to score in four separate World Cups, joining Germans Miroslav Klose and Uwe Seeler and Brazil legend Pele.

And the Portuguese is now also the first player in history to score in eight consecutive major tournaments in a streak going back to Euro 2004.

He is only just getting started on this latest tilt at the pinnacle of the game. And with him in their ranks, who would bet against the Portuguese?

Spain show glimpses of beauty

There were so many sub-plots in play on this humid night in the south of Russia, not least Lopetegui's departure. and how interim manager Hierro would fare in his place.

After the week Spain have had some suggested they should no longer be considered among the favourites to win this competition. From the first half, it looked like things would get much worse for them before it got any better.

Nacho's naive trip was a terrible start, no way to help alleviate the nerves, and there was never any doubt how Ronaldo would deal with the occasion. De Gea was sent the wrong way.

The bad signs kept coming. Busquets, of all people, fell over on the ball and got booked fouling his man. Ronaldo looked so ready for the occasion you would have backed him to smash the resulting free-kick into the net. Instead it hit a head in the wall and Spain survived.

That they did owes much to the heroic block from Jordi Alba just before Costa's first goal, and despite De Gea's error sending them behind once more, they emerged from the break with cool heads that searched for and found the fluency so characteristic of the football they have played since the European Championship-winning side of 2008. That must be applauded.

There had been so many questions raised in the build-up to this game about Spain's mental state but this gutsy performance, in which they showed beautiful glimpses of their real ability, has provided a comprehensive answer, despite Ronaldo's late blow.

Man of the match - Cristiano Ronaldo

More Ronaldo records - match stats

Ronaldo is the oldest hat-trick scorer in World Cup history, with the Portuguese star aged 33 years and 130 days - the previous oldest was Rob Rensenbrink in June 1978 for the Netherlands against Iran (30y 335d).

He scored his 51st hat-trick for club and country, while it was also the 51st hat-trick scored in the history of the World Cup.

His third goal was his first direct free-kick goal at a major tournament for Portugal - it was his 45th attempt.

Spain have now won their opening World Cup match in just two of their last 13 tournaments (D4 L7 - winning in 2002 and 2006).

Spain striker Diego Costa scored with his first two shots on target at the World Cup.

'My personal best' - reaction

Portugal forward Cristiano Ronaldo: "I'm very happy, it is a personal best [the hat-trick], one more in my career and the most important thing is to highlight what the team has done.

"We have played one of the favourite teams to win the World Cup, we have been winning twice and drew and I think it was a fair result. The game was about to end and we managed to equalise so we are happy. Now we have to think about the next match, it is going to be hard, but our goal is to win and to move on from the group stage.

"Portugal is going to start moving through the group stage, we know it is going to be hard, and have to think match by match. We are not the favourites so we will try to do our best. The team is doing very well and we are going to do well for sure."

Spain coach Fernando Hierro: "We feel very proud of the players, we have come back and equalised twice so we feel a great commitment and pride.

"This is a mature squad, the team knows what it wants and have been playing a lot together. It is wonderful to have these mature, committed players.

"When you are playing a player like Ronaldo these things can happen. When you have a player like Ronaldo, it is extremely fortunate for whichever team has him, but I certainly would not change him for any of the players in my squad.

"We don't have any doubts about De Gea and he doesn't have any doubts about himself."

What's next?

Spain's next Group B game is on Wednesday, against Iran in Kazan (19:00 BST). Portugal play Morocco on the same day (13:00).