Marco Simoncelli claimed the first pole position of his career after qualifying fastest for Sunday's Catalunya MotoGP.
The Italian's late lap of one minute 42.413 seconds knocked Casey Stoner into second, with Jorge Lorenzo third.
Simoncelli was the target of much pre-race criticism after a collision with Dani Pedrosa in France which put the Spaniard out of his home race.
"It's the best way after the incident in the last race and a lot of polemic - I'm happy," said Simoncelli.
"I didn't expect [to be fastest] because Stoner was fast for all the session, but in the last part of qualifying we found a good set-up. I'm happy and confident for tomorrow."
Stoner had been quickest in the three practice sessions and was on course for his fourth pole in five races, until Simoncelli beat his time by just 0.016 seconds right at the end of qualifying.
Catalunya MotoGP qualfying results:
1 M Simoncelli (It) Gresini Honda 1'42.413
2 C Stoner (Aus) Repsol Honda 1'42.429
3 J Lorenzo (Sp) Yamaha 1'42.728
4 B Spies (US) Yamaha 1'42.742
5 A Dovizioso (It) Repsol Honda 1'42.749
6 C Crutchlow (GB) Tech 3 Yamaha 1'43.202
7 V Rossi (It) Ducati 1'43.223
8 N Hayden (USA) Ducati 1'43.228
9 A Bautista (Sp) Rizla Suzuki 1'43.447
10 H Barbera (Sp) Aspar Ducati 1'43.656
11 H Aayama (Jpn) Gresini Honda 1'43.734
12 R de Puniet (Fr) Pramac Ducati 1'43.764
13 L Capirossi (It) Pramac Ducati 1'44.068
14 T Elias (Sp) LCR Honda MotoGP Honda 1'44.510
15 K Abraham (Cze) Ducati 1'45.661
1 S Bradl (Ger) Kalex 1:46.753
2 A Espargaro (Sp) Pons Kalex @ 0.114 secs
3 Y Takahashi (Jpn) Moriwaki @ 0.225 secs
125cc qualifying result:
1 N Terol (Spa) Aprilia 1min 51.281secs
2 H Faubel (Spa) Aprilia 1:51.683
3 M Vinales (Spa) Aprilia 1:52.099