Dani Pedrosa snatched pole position in the final moments of qualifying for the Italian Grand Prix at Mugello.
Jorge Lorenzo had been in top spot for most of the session before the late intervention of Pedrosa, who earned his first pole position of the season.
Italian Andrea Dovizioso will line up third, ahead of Cal Crutchlow.
After crashing with eight minutes of the session remaining, Crutchlow climbed on to his spare Monster Yamaha Tech 3 to secure fourth place.
Young Spanish star Marc Marquez, who suffered a spectacular 200mph crash in practice on Friday, was sixth fastest.
The rookie Honda rider, 20, has finished on the podium in every race so far this season but crashed in all three practice sessions on Friday, cracked the top of his humerus near his right shoulder.
"I had almost no time left and I was only sixth fastest," said world championship leader Pedrosa after leaving it late to thwart Yamaha's Lorenzo.
"I had to really push hard and it worked for me. However, I hope we can improve the bike a bit for tomorrow so we can up the pace."
The Repsol Honda rider will be aiming for a hat-trick of victories but Lorenzo, who won at Mugello last year, will be desperate to stop his fellow Spaniard.
"When I saw my lap time I expected to be in pole but it was an incredible lap by Dani," said Lorenzo. "We have good pace for fighting with him on Sunday."
American Ben Spies, who suffered a serious shoulder injury last October, was forced to abandoned his return to racing because he was in too much pain.
In the Moto2 class, British rider Scott Redding - who leads the championship by 24 points - took pole position.
1. Dani Pedrosa (Spa) Repsol Honda 1 minute 47.157 seconds
2. Jorge Lorenzo (Spa) Yamaha 1:47.226
3. Andrea Dovizioso (Ita) Ducati 1:47.628
4. Cal Crutchlow (GB) Tech 3 Yamaha 1:47.632
5. Stefan Bradl (Ger) Honda 1:47.737
6. Marc Marquez (Spa) Honda 1:47.763
7. Valentino Rossi (Ita) Yamaha 1:47.872
8. Nicky Hayden (US) Ducati 1:48.006
9. Alvaro Bautista (Spa) Honda 1:48.355
10. Michele Pirro (Ita) Ducati 1:48.564