Jorge Martin wins fourth straight sprint at Indonesia GP to take championship lead
Martin, who started on the second row in sixth place, held off a late charge by pole-sitter Luca Marini, with Marini's VR46 Racing team-mate Marco Bezzecchi coming in third.
"I feel super! Starting from sixth place maybe was not the best, it's definitely not the best for tomorrow's race," Martin said.
"But I was able to overtake on this track, where normally it's so difficult. Winning was tough, because Luca was coming up really fast in the end, but leading the championship at this point feels great.
"It's a dream. I'm so, so happy to be in the front, hopefully tomorrow we can finish the weekend in the same way."
The Spaniard turned on the aggression as soon as he shot off the mark, moving into fourth place before barrelling past Fabio Quartararo, Luca Marini and Maverick Vinales (Aprilia) into first place.
VR46 Racing also had cause to celebrate, with their two riders putting in heroic performances to claim podium finishes despite having both suffered collarbone injuries in recent weeks.
"Until Wednesday morning, I didn't even know whether I start or not," said Bezzecchi, who underwent surgery earlier this month on a broken collarbone.
"It's fantastic to be here. I was a bit lucky in the race but I was very fast. After the operation, the team did an unbelievable job. I really want to thank my trainer, my doctor and my team, because they made it possible for me to come here."
World champion Bagnaia, who started in 13th after failing to qualify from Q1, finished in eighth place behind team-mate Enea Bastianini.
There was some consolation for Ducati, however, as they retained the constructor's championship on Saturday.
Honda's six-times MotoGP world champion Marc Marquez, who confirmed earlier this week that he will be joining Gresini Racing for the 2024 season, crashed out in the first lap.