Bagnaia came through from 13th on the grid to score his sixth grand prix victory of the season at Mandalika and take an 18-point lead in the championship.
It comes just a day after he lost the standings lead for the first time since before the Spanish GP to Martin, who dominated the sprint to move seven points clear of a struggling Bagnaia.
But Bagnaia was much more competitive on Sunday, and capitalised on a crash for Martin while he was leading by three seconds on lap 13 of 27.
Asked what he thought when he saw the Pramac rider in the gravel, Bagnaia said: “My goal today was to win. The only objective was to win.
“When I saw I was third my thinking was that. When I saw him crash, I could breathe a bit because I was not needing to push so much.
“I was in control and the rear tyre was starting to drop a bit. So, it was very important to stay more constant.”
Bagnaia’s Indonesian GP win marks his first Sunday success since Austria, after which he saw a 66-point lead eroded by Martin through injury and error.
“From my side, this victory means many things,” he added.
“We were so competitive again, and I was missing it a bit because many times I’ve been struggling.
“So, to have this performance again was very, very important. To win is always very important and in a moment when Jorge was out, the main thing was to take the most points as possible.
“And we did that. But from my side, after the crash in Barcelona it was not an easy period.
“And honestly winning today is giving us a lot of motivation – not only for me, but also for my team. They are trying always to give the maximum possible.
“And also this weekend we managed to improve our situation a lot. This morning we improved a bit and in the race even more.”
Bagnaia suffered heavy bruising on his leg from his Catalan GP incident, which affected him in the following races, but he also revealed Indonesia was the first round since Le Mans that he has not been carrying injury.
“After Le Mans, I broke the foot and the wrist,” he said.
“And honestly it was quite hard to ride. Obviously, when you take painkillers you don’t feel anything.
“But then the days after you start to feel not so good. I raced in Mugello and it was ok, but we arrived to the Sachsenring [where it’s] all left corners and I started to have some problems with the ligament in the hand.
“The bone I broke in the foot was like the scaphoid in the wrist and it takes a long time to be ok.
“When I arrived to Barcelona it was finally ok, and then the haematoma I had on my leg was incredible after the crash.
“This weekend was the first weekend without any problems on the leg and it was great for sure.”