Luca Marini sets lap record to grab pole position at Indonesia GP
Marini first set a record with a scorching lap of 01:30.383 in Q1, before topping the timesheets by improving on his own mark in Q2 with a time of 01:29.978 to earn his first-ever pole.
The Italian, who fractured his collarbone at last month's Indian Grand Prix, is the first rider to break the 1 minute and 30-second mark at the Mandalika International Street Circuit.
"It's amazing. It's a period where I'm feeling so comfortable with the bike, I'm so strong and fast," Marini said.
"We had some problems in practice yesterday, but we understood what those problems are in the evening and we fixed it. This morning the bike was very good, I had a good feeling with the tyres.
"I'm really satisfied with the work we have done in these two days. I think the sprint and Sunday's race will be really tough. I expect Aprilia to be stronger than us but I will do my best and give 100% and let's see what we can achieve."
Aprilia duo Maverick Vinales and Aleix Espargaro finished second and third, while Pramac Racing's Jorge Martin, just three points behind Bagnaia in the overall standings, will be disappointed to end in sixth place.
However, Spaniard Martin, who crashed during his second lap in Q2, still has a strong chance to leapfrog Bagnaia for the championship lead, with the Italian starting 13th on the grid.
Ducati's Bagnaia cut a frustrated figure in Q1 as he appeared set to progress to Q2 after a quick final lap, but was bumped off the top two spots by his team-mate Enea Bastianini and Marini.
Marco Bezzecchi, third in the overall standings, ended in ninth after also suffering an early crash.