From formulaic through to a denouement that simply could not have been scripted, the streets of Baku were once again the stage for a compelling, dramatic performance. Where cool heads were called for at the Azerbaijan Grand Prix there was not a little abandon and in its wake fortune too played its part to deliver an unlikely result in a season already notable for refusing to stick to a predictable plot.

Lewis Hamilton took the win but it is unlikely to be a favoured memory. He inherited first place with two laps to go from his Mercedes team-mate Valtteri Bottas, who had looked nailed on for the victory until a puncture caused by debris ended his charge, leaving the Finn disconsolate.

Behind Hamilton his championship rival, Ferrari’s Sebastian Vettel, for some time in control of the race, saw his hopes disappear after a late safety car when he sacrificed calm consideration for an overambitious lunge that reduced him to fourth place.

This most unlikely turnaround at the front was reflected in an equally unexpected reversal of the championship standings. Trailing Vettel by nine points before Baku, Hamilton leaves four points to the good, the first time he has topped the table this season.

Hamilton, who had not been on the pace all weekend and never looked like threatening for the lead, was honest about his good fortune. “It was mixed emotions,” he said. “Grateful for the opportunity to win but on the other side I did not drive the way I feel like I normally drive, so that hurts a little bit in my heart.”

A likely win at the first round in Melbourne was denied Hamilton after a late safety car and he may feel that some justice has been served. But perhaps there will be more satisfaction that his chance of a win here last year was ultimately denied after Vettel barged him. “I was coming out of the last corner in disbelief,” he said. “It was very emotional. In previous years here I have been in the lead and then something went against me. I said maybe third time lucky and it was that scenario today.”

Bottas’s ill-fortune and Hamilton’s good favour was the final part of a thrilling last act. Behind them the Red Bulls had been offering a fine narrative of their own, with Daniel Ricciardo and Max Verstappen going wheel to wheel throughout. It was nail-biting stuff but the team had let them race, a decision they came to regret when the Australian went for a pass into the braking zone of turn one. Verstappen had already moved once and then shifted back to the inside where Ricciardo had committed. A terminal collision ensued. The stewards concluded that both were responsible, Verstappen for changing lines twice and Ricciardo for making his move too late. Both were given reprimands.

Disappointment was writ large on the faces of the drivers, but that was as nothing to the condemnation from the team principal, Christian Horner. “We are not apportioning blame, they are both to blame,” he said. “They have been reminded that they are part of a team, they are highly paid individuals and have to act with the team’s interests at heart, not just their own. That message was delivered very clearly.”

The safety car the incident caused proved crucial. It allowed Mercedes to pit Bottas, who had stayed out long on his tyres and inherited the lead, to emerge still in front of Vettel.

A further lack of focus saw Romain Grosjean put his Haas into the wall on lap 43 while weaving, and that kept the safety car out longer than expected. Five laps later at the restart Bottas had control, but Vettel did not. He charged up the inside into one, far too hot, locked up, went wide and lost places to Hamilton and Kimi Räikkönen, who was second, and then to Force India’s Sergio Pérez who took third, his team’s first podium of the year.

It was not the percentage manoeuvre of a championship contender but the German insisted he had no regrets. “I am happy I tried the move. I am not happy it didn’t work. You have to try.” That’s a view he may come to consider again if the season goes to the wire.

A lap later Bottas had to face his own slings and arrows, grinding to a halt amid disintegrating rubber. “It was just unfortunate. Unlucky. Ten pints of beer and maybe I will be fine,” said the visibly disappointed Finn. “I will get through it, you always have to get through, it is part of racing but at the moment it is painful.”

Hamilton felt for Bottas but knows that he and his team have real work ahead. Their issue with bringing the tyres up to temperature looked no closer to being solved in Baku and he acknowledged that they had to address it.

For the moment, however, he leaves with a lead, favoured by fortune but also more than aware that he kept his head and seized the reward. It was cause for the four-times world champion to remember the lesson he had learned in karting. “I never give up,” he said. “It has been a while since I have been reminded of that lesson my dad taught me years ago. I kept pushing and things turned out the way they did and that was a realisation of how true that mindset is.”

Carlos Sainz in the Renault finished in fifth, while Charles Leclerc completed an exemplary afternoon and the rookie’s best drive thus far in F1 to take sixth for Sauber. The two McLarens of Fernando Alonso and Stoffel Vandoorne were seventh and ninth, with Lance Stroll eighth in the Williams and the Toro Rosso of Brendon Hartley 10th.