Pecco Bagnaia won the German Grand Prix to take the MotoGP 2024 championship lead, as main rival Jorge Martin crashed out of first place on the penultimate lap.
Marc Marquez fought through from 13th to second despite a big collision with Pramac Ducati's Franco Morbidelli.
Having lost the lead off the line on Saturday, Martin fought off a Miguel Oliveira challenge through the first two corners to keep it this time - but Bagnaia pulled off an overtake on each the first two times through the final corner to lead at the start of the third lap.
Martin stayed close to Bagnaia, having also fought off an attack from his charging team-mate Morbidelli, and then moved back past Bagnaia by braking late and going deep on the inside of Turn 1.
Now in clean air, Martin established a bit of breathing space, aided by team-mate Morbidelli ducking out of Bagnaia's tow to pull off a Turn 1 lunge of his own a couple of laps later.
But Morbidelli's pace dropped off soon after, with Bagnaia getting back through in the penultimate corner as the 30-lap race arrived at its halfway point, setting up a late-race duel between himself and the rider he had been chasing in the championship.
Bagnaia quickly took a few tenths out of Martin, but every time he got to within six tenths Martin seemed to be able to respond.
But when Bagnaia threatened a last-gasp attack and Martin responded again, the Pramac rider fell off at Turn 1, handing the win to his adversary and falling 10 points behind him in a 30-point swing.
Marquez could've been part of that battle but a messy Friday and Saturday had left him 13th on the grid and he did not make progress quickly enough.
Ninth after the opening lap, he slowly but surely worked his way towards the back of the leading pack - but a victory challenge was already out of the question when Morbidelli ran wide at Turn 1 ahead of Marquez and the two Ducatis collided as he rejoined the racing line.
Marquez ultimately shrugged off the impact, and overtook Morbidelli at the final corner a handful of laps later.
He then reeled in his brother Alex Marquez and overtook him, but by that point the brothers were already on course to share the podium following Martin's crash - which they did in the end.
Enea Bastianini defeated Morbidelli in a late duel to claim fourth place, with Morbidelli wrapping up a Ducati 1-2-3-4-5.
Miguel Oliveira didn't quite reach the heady heights of Saturday on his Trackhouse-run Aprilia, but still scored a credible sixth, while Pedro Acosta and Marco Bezzecchi worked their way past Brad Binder on the final lap for seventh and eighth respectively and Raul Fernandez completed the top 10.
Maverick Vinales was running in the top 10 when he went off at Turn 7. He'd recovered to 12th by the finish.
Takaaki Nakagami denied Honda stablemate Luca Marini his first point of the season in a final-lap battle for 15th, albeit Marini may still be on course to score as Augusto Fernandez - who finished 14th - is under investigation for a potential tyre pressure infringement.
Yamaha's Alex Rins stand-in Remy Gardner had a pretty quiet race to 20th and last, in what had otherwise been an impressive weekend.
The only other retirement besides Martin was Fabio Di Giannantonio, pulling his Ducati into the pits and glaring at the rear of the bike as he disembarked it.