Andrea Iannone produced a blistering final lap to take pole in the Austrian MotoGP and championship leader Marc Marquez qualified in fifth despite dislocating his shoulder in a heavy crash in practice on Saturday.
Valentino Rossi looked set to start Sunday's race at the Red Bull Ring at the front of the grid, but had to settle for second after fellow Italian Iannone snatched pole in a dramatic second qualifying session.
Iannone damaged his ribs in a motocross accident during the summer break, but the Ducati rider sealed the second pole of his career right at the end of FP2.
Ducati team-mates Andrea Dovizioso and Iannone won FP3 and FP4 respectively before the latter delivered when it really mattered with a lap of one minute 23.142 seconds as the last man out in Q2.
Dovizioso was third behind Movistar Yamaha's Rossi, who had been off the pace in some sessions at the first Austrian MotoGP since 1997.
There were concerns over Marquez, leading second-placed Jorge Lorenzo by 48 points, when he lost control at turn three in FP3 and picked himself up from the gravel holding his left shoulder.
The Repsol Honda rider put his shoulder back in place before being taken to hospital for a scan and returned to seal his place in second after being given the all clear.
Lorenzo could only qualify in fourth, with Maverick Vinales making it an all-Spain second row. Dani Pedrosa was down in 12th after crashing on Friday.
1. Andrea Iannone (Ducati) 1:23.142sec
2. Valentino Rossi (Movistar Yamaha) 1:23.289s
3. Andrea Dovizioso (Ducati) 1:23.298s
4. Jorge Lorenzo (Movistar Yamaha) 1:23.361s
5. Marc Marquez (Repsol Honda) 1:23.475s
6. Maverick Vinales (Suzuki Ecstar) 1:23.584s
7. Cal Crutchlow (LCR Honda) 1:23.597s
8. Scott Redding (OCTO Pramac Yakhnich) 1:23.777s
9. Aleix Espargaro (Suzuki Ecstar) 1:23.813s
10. Hector Barbera (Avintia Racing) 1:23.822s