Lewis Hamilton was handed victory in a madcap finish to a chaotic, incident-strewn Azerbaijan Grand Prix during which both Red Bulls sensationally collided with each other.
Hamilton's team-mate Valtteri Bottas was on course to win after Mercedes took advantage of a late safety car to jump long-time leader Sebastian Vettel's Ferrari.
But, after Vettel had thrown away second place with a mistake at the restart, Bottas suffered a puncture on the next lap.
His two rivals out of the way, Hamilton was given victory and the championship lead on a plate after looking set to finish third.
- Listen: Verstappen and Ricciardo collide
- Listen: 'It just blew on its own!' - Bottas
- Azerbaijan Grand Prix results
- 5 live F1 race review
There will be words
The late safety car had been triggered by a crash between the two Red Bulls, when Daniel Ricciardo slammed into the back of team-mate Max Verstappen while trying to pass into the first corner.
There will be recriminations at Red Bull, whose drivers had appeared on the edge of a crash for much of the race as Ricciardo fought to pass Verstappen and the Dutchman defended right on the edge of acceptability, and some might say beyond.
Red Bull are well known for employing two drivers who fight fiercely on track, but there has not been a coming together of this magnitude since Vettel and Mark Webber ended each other's race during the Turkish Grand Prix in 2010.
But although their incident - for which they both received a reprimand from race stewards - will generate headlines they had a bit part in a race that for so long Vettel looked to have in a headlock.
How did Vettel lose that?
The German led from pole and, after a safety car was triggered by several first-lap crashes, built a three-second lead on the first racing lap.
Hamilton could not quite stay with Vettel and his hopes appeared to be over when he locked his wheels going into Turn One on lap 22.
That forced him to stop for fresh tyres and demoted him to third place, and now there was a cat-and-mouse game between Vettel and Bottas.
Vettel and Ferrari stuck it out with a conventional strategy, stopping on lap 28 for soft tyres, while Mercedes left Bottas out hoping for a safety-car period.
It came, thanks to the Red Bulls, as Ricciardo cannoned into the back of Verstappen.
As a stop under the safety car costs less time than one in racing conditions, Bottas was able to emerge in the lead.
The question of whether he could hold off Vettel in what appeared to be a faster car became academic when the German lunged for the inside at the restart with four laps left and ran wide, letting Hamilton and the second Ferrari of Kimi Raikkonen through. Force India's Sergio Perez moved past into third soon afterwards.
Bottas then seemed set for the win, but ran over debris on the next lap and suffered a major tyre failure as he passed the pits with three laps to go.
Hamilton, who took his first win since last October's US Grand Prix and a four-point championship lead over Vettel, was disbelieving afterwards.
"Really quite an emotional race," he said. "Valtteri did such an exceptional job and really deserved the win. I was very fortunate. It feels a bit odd, but I've got to take it."
How the Red Bull madness unfolded
The Red Bulls were expected to contend for victory but, instead, in the opening laps found themselves under pressure from the Renaults of Carlos Sainz and Nico Hulkenberg, who were on softer tyres.
Verstappen's passing move on Ricciardo at Turn Two at the first restart on lap six let Sainz past the Australian and the Spaniard was soon past the Dutchman, too.
After Hulkenberg took himself out of the reckoning by hitting the wall in his second unforced error in Baku in two races, the Red Bulls set to it.
Ricciardo was obviously faster, and tried several times to pass Verstappen, the edgiest moment when the Dutchman nudged his team-mate to the wall in Turn One as Ricciardo tried to pass around the outside on lap 12.
Ricciardo settled back for a while but then attacked again on 35, this time succeeding in his outside move at Turn One.
But, when they pitted two laps apart on laps 38 and 39, Ricciardo somehow lost out despite stopping first, which should give an advantage.
Next time around, Ricciardo sought to make amends. He dummied to the outside, Verstappen defended and then defended again to the inside, and Ricciardo locked his brakes and smashed into the back of his team-mate, the pair spinning into the run-off area.
The incident will cause controversy - and while Ricciardo undoubtedly misjudged it, there will be those who feel Verstappen paid the price for moving too many times in the braking zone, something he has made a controversial trademark since his debut.
Mercedes non-executive director Niki Lauda sided with Ricciardo, saying the incident was "70% Verstappen's fault because he moved too many times".
There may also be an argument the team should have intervened earlier, knowing the intensity of the drivers' personal battle, and given Ricciardo was clearly the quicker driver on this day.
Another mad restart
There was even drama during the final safety-car period, when Haas driver Romain Grosjean spun out of seventh place while trying to warm his tyres.
Hamilton criticised race director Charlie Whiting for not stopping the race, rather than sending out a flat-bed truck to recover Grosjean's car.
That decision would also have provided more racing laps at the end.
Vettel, after his error at the final restart, survived to finish fourth, ahead of Sainz, a stellar performance by rookie Charles Leclerc in the Sauber and McLaren's Fernando Alonso, seventh despite suffering two punctures and floor damage when caught in a first-lap incident with Hulkenberg and Williams' Sergey Sirotkin.
Sirotkin was later handed a three-place grid penalty at the next race for running into the back of Sergio Perez during that opening lap.
Driver of the day
What happens next?
F1 returns to Europe in two weeks' time for the Spanish Grand Prix, where everyone will have updates to their cars and Mercedes will be seeking to overturn Ferrari's obvious pace advantage.