Reigning world champion Francesco Bagnaia held off a frantic late counter-attack by Brad Binder in Jerez on Sunday to win the Spanish Grand Prix and take the lead in the MotoGP standings.
Italian Bagnaia, on a factory Ducati, overtook South African Binder, on a KTM, with four laps to go and resisted a fightback.
Australian Jack Miller, who led for the first half of the race, was third on another KTM.
Bagnaia struggled in practice on Friday and had to go through the qualifying repechage to earn a chance to compete for a place on the first four rows on the starting grid.
"Very long weekend," he said. "I was a bit in trouble Friday. I needed time to be used to this bike on this track."
The race was quickly halted on Sunday after Fabio Quartararo, Miguel Oliveira and pre-race championship leader Marco Bezzecchi all crashed on the opening lap.
It was also punctuated by penalties with both Bagnaia and Miller among those forced to give up a place mid-race.
Binder and Bagnaia were both attempting to bounce back after two bad results on the Americas and the South African edged the sprint the evening before.
On Sunday, Binder could not hold off the Italian.
"It was fantastic to finish the main race again today the last two I messed up," Binder said.
"It was nice to be out front and lead. I kept seeing a little gap. I thought 'OK I've done the job. I just need to be sure I don't mess up the edge of my rear tyre' and I think I cooked it with three laps to go.
"Hats off to Pecco. He pushed me the whole way and got me in the end."
Bagnaia, who crashed out in the United States and Argentina, overtook compatriot Bezzecchi in the standings.
Miller said he was surprised by the face over the final laps.
"I don't know why, but we started putting in really fast laps towards the end but we weren't closing, so the others were doing it too," he said.
Spaniard Jorge Martin (Ducati-Pramac) was fourth ahead of fellow Spaniard Aleix Espargaro (Aprilia), who was on pole but started badly and was never in a position to fight for victory