Jorge Lorenzo held on for a home MotoGP pole position at Jerez as many of his main rivals crashed.
Dani Pedrosa will start second, 0.247 seconds away from Lorenzo, having been one of the men to fall in the dramatic closing minutes.
Valentino Rossi and Cal Crutchlow also crashed. Like Pedrosa, both were unhurt.
Marc Marquez had got his crash out of the way in the practice four session just before qualifying. He stayed upright in the pole shootout and completes the front row.
Yamaha rider Lorenzo was on top for the majority of Q2, improving to a 1m38.673s to seal the place.
Pedrosa's high-speed fall came as he was trying to respond, and was followed just moments later by a similar incident for Rossi. Their respective Honda and Yamaha bikes sustained hefty damage, but the riders were unscathed.
Marquez's incident had been far less spectacular - the Austin winner sliding off in a low-speed low-side in final practice.
Within just four minutes of his violent fall early in Q2, Crutchlow was back in the pits and jumping on his spare Tech 3 Yamaha.
Despite a gallant effort in gravel-covered leathers, the Briton could not improve and remained fourth, ahead of Rossi and Alvaro Bautista.
Nicky Hayden was the quickest of the Ducatis in seventh.
Hector Barbera's stunning practice form continued as the Avintia man became the only CRT rider to reach Q2, doing so at the expense of Ducati guest Michele Pirro.
Barbera then became yet another crasher in Q2, yet still beat Andrea Iannone and Bradley Smith to 10th on the grid.
Iannone had mitigating circumstances, as he had a nasty fall in Q1, sustaining severe leg cuts.
Completing the incident list, both Lukas Pesek and Colin Edwards crashed their bikes during the opening segment.
Pos Rider Team/Bike Time Gap
1. Jorge Lorenzo Yamaha 1m38.673s
2. Dani Pedrosa Honda 1m38.920s + 0.247s
3. Marc Marquez Honda 1m38.971s + 0.298s
4. Cal Crutchlow Tech 3 Yamaha 1m39.262s + 0.589s
5. Valentino Rossi Yamaha 1m39.300s + 0.627s
6. Alvaro Bautista Gresini Honda 1m39.509s + 0.836s
7. Nicky Hayden Ducati 1m39.654s + 0.981s
8. Stefan Bradl LCR Honda 1m39.847s + 1.174s
9. Andrea Dovizioso Ducati 1m39.848s + 1.175s
10. Hector Barbera Avintia FTR-Kawasaki 1m39.980s + 1.307s
11. Andrea Iannone Pramac Ducati 1m40.087s + 1.414s
12. Bradley Smith Tech 3 Yamaha 1m40.356s + 1.683s
13. Aleix Espargaro Aspar Aprilia 1m40.085s + 1.412s
14. Michele Pirro Ducati 1m40.182s + 1.509s
15. Randy de Puniet Aspar Aprilia 1m40.466s + 1.793s
16. Hiroshi Aoyama Avintia FTR-Kawasaki 1m40.654s + 1.981s
17. Danilo Petrucci Ioda-Suter-BMW 1m40.852s + 2.179s
18. Bryan Staring Gresini FTR-Honda 1m41.324s + 2.651s
19. Claudio Corti Forward FTR-Kawasaki 1m41.513s + 2.840s
20. Colin Edwards Forward FTR-Kawasaki 1m41.536s + 2.863s
21. Yonny Hernandez Paul Bird Aprilia 1m41.779s + 3.106s
22. Michael Laverty Paul Bird PBM-Aprilia 1m41.935s + 3.262s
23. Lukas Pesek Ioda-Suter-BMW 1m43.220s + 4.547s