Dani Pedrosa edged out championship leader Jorge Lorenzo to take pole for Sunday's Italian Grand Prix at Mugello.
The Spanish duo exchanged fastest lap times throughout qualifying but it was Repsol Honda's Pedrosa who prevailed.
Lorenzo had looked set to pip him when he started a flying lap in the dying moments, only to pull into the pits, citing "electrical problems".
Hector Barbera finished third ahead of Nicky Hayden, with world champion Casey Stoner fifth and Cal Crutchlow sixth.
Pedrosa told BBC Sport: "The lap time was pretty good, we want to improve a little more for the race tomorrow. It is important to be at the front doing consistent laps."
But Lorenzo was unable to hide his frustration after being forced to abort his flying lap in the closing seconds.
"We had electrical problems in the last two laps. We will have to check them out. I'm very disappointed because we have been very fast here," he said.
It was, however, an impressive showing from Barbera, who sits 11th in the World Championship standings, as he ensured it will be an all-Spanish front row in Italy.
Stoner, having struggled for much of the session with the set-up of his Honda, managed to salvage a spot on the second row after climbing up the grid in the closing stages.
Pol Espargaro of Spain claimed pole in Moto2 with British pair Bradley Smith and Scott Redding seventh and eighth respectively, while Maverick Vinales clinched first position in qualifying in the Moto3.
Moto GP qualifying:
1. Dani Pedrosa (Spa) Repsol Honda 1:47.284
2. Jorge Lorenzo (Spa) Yamaha 1:47.423
3. Hector Barbera (Spa) Pramac 1:47.545
4. Nicky Hayden (USA) Ducati 1:47.671
5. Casey Stoner (Aus) Repsol Honda 1:47.689
6. Cal Crutchlow (GB) Tech 3 Yamaha 1:47.749
7. Andrea Dovizioso (Ita) Tech 3 Yamaha 1:47.751
8. Stefan Bradl (Ger) LCR Honda 1:47.857
9. Ben Spies (USA) Yamaha 1:48.149
10. Valentino Rossi (Ita) Ducati 1:48.502
1 Pol Espargaro (Spa) Pons Kalex 1:52.369
2 Marc Marquez (Spa) Suter 1:52.438
3 Johann Zarco (Fra) Motobi 1:52.781
7 Bradley Smith (GB) Tech 3 1:53.029
8 Scott Redding (GB) Marc VDS Kalex 1:53.059
25 Gino Rea (GB) Gresini Suter 1:54.513
1 Maverick Vinales (Spa) FTR 1:57.980
2 Sandro Cortese (Ger) KTM 1:58.401
3 Alex Rins (Spa) Suter 1:58.821