Defending champion Marc Marquez denied Alvaro Bautista pole with a stunning last-gasp lap in a tense qualifying session for the 2014 MotoGP season-opening Qatar Grand Prix.
Pre-session favourite Aleix Espargaro, who whitewashed practice at the Losail track, crashed twice and wound up ninth overall.
The latter fall came one minute from the chequered flag, and while he was up on the provisional pole time - which at that point belonged to Bautista.
The Spaniard seemed set for only his second career pole, but as the chequered flag flew Marquez - riding with a broken leg - came round in 1m54.507s to snatch top spot by just over five hundredths of a second.
Bradley Smith will start from the front row for the first time in his premier class career, having also got within 0.1s of Marquez's pole time.
MotoGP 2014: The key storylines
Ducati's Andrea Dovizioso meanwhile shaded Factory riders Jorge Lorenzo and Dani Pedrosa in the fight for fourth.
Stefan Bradl and Cal Crutchlow will share row three with Espargaro, with Valentino Rossi therefore consigned to the fourth row alongside Andrea Iannone and Pol Espargaro.
The latter prevailed in QP1 alongside Cal Crutchlow, although both were made to sweat when Nicky Hayden threatened an upset in the final two minutes.
The Aspar Honda rider dipped under Crutchlow's best in the first sector, but ultimately fell a few tenths short of demoting the Briton.
Hayden will therefore start from 13th, ahead of compatriot Colin Edwards and team-mate Hiroshi Aoyama.
Scott Redding suffered a recurrence of earlier electrical gremlins but was able to secure 16th ahead of Pramac's Yonny Hernandez, who crashed heavily at Turn 2 in the opening minutes of the session.
Pos Rider Team/Bike Time Gap
1. Marc Marquez Honda 1m54.507s
2. Alvaro Bautista Gresini Honda 1m54.564s +0.057s
3. Bradley Smith Tech 3 Yamaha 1m54.601s +0.094s
4. Andrea Dovizioso Ducati 1m54.644s +0.137s
5. Jorge Lorenzo Yamaha 1m54.661s +0.154s
6. Dani Pedrosa Honda 1m54.703s +0.196s
7. Stefan Bradl LCR Honda 1m54.871s +0.364s
8. Cal Crutchlow Ducati 1m54.888s +0.381s
9. Aleix Espargaro Forward Yamaha 1m54.986s +0.479s
10. Valentino Rossi Yamaha 1m55.096s +0.589s
11. Andrea Iannone Pramac Ducati 1m55.127s +0.620s
12. Pol Espargaro Tech 3 Yamaha 1m55.152s +0.645s
13. Nicky Hayden Aspar Honda 1m55.894s Q1
14. Colin Edwards Forward Yamaha 1m56.042s Q1
15. Hiroshi Aoyama Aspar Honda 1m56.479s Q1
16. Scott Redding Gresini Honda 1m56.555s Q1
17. Yonny Hernandez Pramac Ducati 1m56.648s Q1
18. Karel Abraham Cardion Honda 1m56.715s Q1
19. Hector Barbera Avintia FTR-Kawasaki 1m57.006s Q1
20. Danilo Petrucci Ioda Aprilia 1m57.513s Q1
21. Broc Parkes PBM Aprilia 1m57.574s Q1
22. Mike di Meglio Avintia FTR-Kawasaki 1m57.667s Q1
23. Michael Laverty PBM Aprilia 1m58.254s Q1