Fabio Quartararo will start MotoGP's Malaysian Grand Prix from pole position for Petronas SRT Yamaha, while Marc Marquez crashed heavily.
Rookie Quartararo put in a blinding 1m58.303s right at the flag to grab pole from fellow Yamaha rider Maverick Vinales.
The lap is the fastest ever set on a MotoGP race weekend at the Sepang circuit - and came so late that Vinales was already celebrating, thinking he'd taken pole position.
Franco Morbidelli made it a Yamaha front-row lock-out with third on the second SRT bike.
Quartararo spent much of the session trying to shake Marquez from his slipstream, the world champion sticking doggedly to the back of the Petronas Yamaha every time it went out.
Quartararo did his best to delay the critical final run hoping Marquez would give up, before biting the bullet with two minutes to go.
But he didn't have Marquez in his tow for long, the Honda rider suffering a spectacular high-side on his way into Turn 2.
Marquez walked away from the frightening accident, but ended up 11th thanks to not setting a time on his final run.
That means he's facing his worst starting position since the 2015 Italian GP.
Jack Miller will start from fourth, joined on the second row by Q1 pacesetter Cal Crutchlow and Valentino Rossi.
Crutchlow couldn't have left his run any later in Q1, the LCR Honda rider only booking his progression right at the flag.
Joan Mir and Danilo Petrucci had spent much of the opening session squabbling over the top two spots, with the Suzuki rider managing to improve just enough on each run to hang on to top spot.
It was only as the chequered flag flew that Petrucci finally wrestled top spot from Mir, his 1m59.336s putting him 0.038s clear.
It proved to be a decisive position change, too, with Crutchlow beating them both with a 1m59.216s - leaving Mir stranded in Q1.
Alex Rins, Petrucci and Johann Zarco secured the third-row spots in Q2, while Andrea Dovizioso was just 10th fastest.
Francesco Bagnaia was slowest in Q2, off the back of a high-speed low-side during practice four.
Jorge Lorenzo will start a disappointing 18th after falling more than a second short of the Q1 pace.
His run into the session was compromised by a bizarre shunt in the closing stages of practice four, when he suffered a low-speed high-side after running wide at Turn 1.
Provisional starting grid
|1||Fabio Quartararo||Petronas Yamaha||1m58.303s||-|
|3||Franco Morbidelli||Petronas Yamaha||1m58.432s||0.129s|
|4||Jack Miller||Pramac Ducati||1m58.725s||0.422s|
|5||Cal Crutchlow||LCR Honda||1m58.951s||0.648s|
|9||Johann Zarco||LCR Honda||1m59.139s||0.836s|
|12||Francesco Bagnaia||Pramac Ducati||1m59.640s||1.337s|
|16||Karel Abraham||Avintia Ducati||2m00.072s||-|
|20||Hafizh Syahrin||Tech3 KTM||2m01.045s||-|