Bagnaia wins Indonesia Grand Prix as Martin throws away championship lead
Bagnaia crossed the line just ahead of Aprilia's Maverick Vinales in second, while Yamaha's Fabio Quartararo, the 2021 world champion, finished third.
"I think we deserved a race like this. I just tried to do the maximum I could in the first few laps," said Bagnaia, who started in 13th after failing to qualify from Q1 in Saturday's qualifying session.
"I tried to take care of the tyres, then in the last laps I was a little out of pace, so I was controlling a lot."
Bagnaia is back on top of the riders' standings with 346 points, with Martin (328) in second and Bezzecchi (283) in third.
Pramac Racing's Martin, who took the championship lead on Saturday after winning the sprint, started from the second row in sixth place but did not stay there long, rocketing off the line in hot conditions to take the lead after the very first turn.
But with the Spaniard cruising with a comfortable lead of over two seconds, his bike went from under him and he was dumped in the gravel, leaving him holding his head in his hands in disbelief at spurning the gilt-edged opportunity.
Pramac Racing had a day to forget, with Johann Zarco also crashing out to compound their misery.
After Martin crashed, Vinales was briefly in the lead but Bagnaia kept up his aggressive riding, slowly and steadily gaining ground on the Aprilia rider before blowing past him in the 20th lap.
"I was running so well, I was trying to control the tyres and Pecco was just a little bit faster than I was," Vinales said.
"I knew from yesterday that if I push and push, my rear tyre would be done, so I tried to control it a bit."
Vinales and Quartararo were locked in an intense duel for third place for much of the final portion of the race, but the Spaniard clung on for a second-place finish.
"It was frustrating. I know my speed. We know what we missed, it's really frustrating when you know what you're capable of," Quartararo said.
Gresini's Fabio Di Giannantonio was fourth and Bezzecchi, racing just days after undergoing surgery on a broken collarbone, finished in fifth, ahead of Red Bull KTM duo Brad Binder and Jack Miller.
Pole-sitter Luca Marini crashed out early on after a coming-together with Binder, while 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, also crashed out.