Valentino Rossi charged to a first MotoGP pole position in almost a year, and first at Jerez since 2005, on his final lap of Saturday's qualifying session in Spain.

Only Jorge Lorenzo and Marc Marquez had held provisional pole until Rossi - looking to rebound from a rare DNF in Texas - suddenly got the better of both his main rivals.

Marquez threatened to snatch pole back on his own last lap, but lost his advantage in the last sector. That confirmed Rossi's 62nd pole by 0.122s from Lorenzo, with Marquez 0.155s behind to complete a mouth-watering front row.

"We work a lot because last year we struggled too much in qualifying," Rossi said. "This year with Michelin I feel better. I already start on the front row twice this year, but a pole position is different - especially here at Jerez. For sure tomorrow will be very hard with Lorenzo and Marquez. But we are there. We can fight."

Rossi's last MotoGP pole was at Assen 2015, where he went on to win the race.

Yamaha team-mate and reigning champion Lorenzo - quickest in three of the four practice sessions prior to qualifying, Rossi led the other - had been planning to make three flying runs in qualifying. However he aborted his second attempt.

"The [second] bike was good, just we got a defective tyre. Chattering on the rear. So we had to cancel the lap. It was a pity," Lorenzo explained. "I didn't feel great on the soft tyre today, but I think for the race we have the pace."

Honda star Marquez confirmed that the pair of fast right-handers leading into the final hairpin had been his undoing.

"The problem is the two fast corners. The Yamaha there is really constant and really precise. I tried to push and improve this last sector, but it was not possible," said the world championship leader. "Anyway, happy with qualifying because we are close and tomorrow we will try to stay with the Yamaha riders."

Forming row two of Sunday's grid will be Ducati's Andrea Dovizioso, who has struggled with the wheelspin generated at Jerez, plus the Suzukis of Maverick Vinales and Aleix Espargaro.

Marquez's Repsol Honda team-mate Dani Pedrosa claimed seventh, ahead of top satellite rider Pol Espargaro (Tech 3) who was also the final rider within one-second of Rossi.

Fellow Spaniard Hector Barbera completes the third row, with Cal Crutchlow and Loris Baz qualifying tenth and twelfth after progressing through Qualifying 1. Dovizioso's team-mate Andrea Iannone will start between them, in eleventh.

Alvaro Bautista narrowly missed out on putting Aprilia into Qualifying 2, while Bradley Smith's record of escaping from Q1 came to an end with 14th on the grid.

Qualifying 2:
1 Valentino Rossi
2 Jorge Lorenzo
3 Marc Marquez
4 Andrea Dovizioso
5 Maverick Vi?ales
6 Aleix Espargaro
7 Dani Pedrosa
8 Pol Espargaro
9 Hector Barbera
10 Cal Crutchlow
11 Andrea Iannone
12 Loris Baz

By Peter McLaren