Valentino Rossi sent Mugello into a frenzy as the Yamaha rider clinched pole for his home MotoGP in a red-hot final qualifying session in Italy.
Ducati's Andrea Iannone had entered Q2 as the favourite to secure his second successive pole at the Italian track after dominating free practice, but it was Rossi who timed his final attack to perfection to seize the top spot on the Movistar Yamaha.
The Doctor used a tow from his future Yamaha team-mate Maverick Vinales to devastating effect, slipstreaming past the factory Suzuki on the main straight to post the fastest time of the weekend in 1m 46.504s for his first Mugello pole since 2008.
Vinales was equally impressive as the young Spanish rider bumped Iannone back to third place on the front row, who had held sway at the summit of the time sheets for much of the session.
The Suzuki rider lapped in 1m 46.598s as he finished only 0.094s back on Rossi, with Iannone 0.103s in arrears as the Italian finalises a front row comprising three different manufacturers.
Confirmed at Suzuki for 2017, Iannone put down an early marker with a time in 1m 46.727s with a blistering lap as he chased after Jorge Lorenzo on track, who began the lap almost a second ahead.
Iannone again improved his time on his second run on the GP16, lapping in 1m 46.607s to extend his advantage over Vinales to 0.143s.
However, in a dramatic final few minutes, Vinales and Rossi left pit lane together and the 37-year-old produced a sensational lap to nail down pole on the YZR-M1, sending his legions of partisan fans wild with delight.
Marc Marquez briefly looked to be a threat on the Repsol Honda in the dying seconds, but his time fell away as the RC213V began to tie itself in knots, leaving the two-time champion to head up row two, 0.255s behind Rossi.
Championship leader Lorenzo could only manage fifth on the Movistar Yamaha, over three tenths behind his team-mate, with Aleix Espargaro on the second Ecstar Suzuki taking sixth on the GSX-RR.
Dani Pedrosa (Repsol Honda), top satellite rider Bradley Smith on the Monster Yamaha Tech 3 and Pramac Ducati's Danilo Petrucci form row three, while Scott Redding (Pramac Ducati), Ducati test rider Michele Pirro and Yonny Hernandez on the Aspar Ducati complete the fourth row.
Andrea Dovizioso continues to struggle on the factory Ducati and will start Sunday's race from 13th on row five, where he is joined by Pol Espargaro (Monster Yamaha Tech 3) and Avintia Ducati's Hector Barbera.
Britain's Cal Crutchlow is back on the sixth row on the LCR Honda with Aussie Jack Miller (Marc VDS Honda) and Ireland's Eugene Laverty (Aspar Ducati).
Aprilia riders Alvaro Bautista and Stefan Bradl plus Loris Baz (Avintia Ducati) bring up the rear of the grid.
1 Valentino Rossi
2 Maverick Viñales
3 Andrea Iannone
4 Marc Marquez
5 Jorge Lorenzo
6 Aleix Espargaro
7 Dani Pedrosa
8 Bradley Smith
9 Danilo Petrucci
10 Scott Redding
11 Michele Pirro
12 Yonny Hernandez