Valentino Rossi came within 0.126s of qualifying as the fastest Yamaha rider ahead of his MotoGP farewell at Valencia on Sunday.

Eager to sign-off his illustrious career with a competitive showing, Rossi delighted his fans by snatching a rare top ten in FP3 - providing vital direct access to Qualifying 2 - then delivered his best qualifying since Silverstone courtesy of tenth on the grid.

With a little help from Francesco Bagnaia.

The factory Ducati star, one of three MotoGP riders whose path to the premier-class was supported by Rossi's VR46 Academy, gave The Doctor a tow in both FP3 and Qualifying.

Nothing was planned, Rossi explained, but each time Bagnaia saw the #46 behind him, he chose to keep pushing in the knowledge it would help the nine-time world champion.

"Pecco helped me, I'm very happy," Rossi said. "We didn’t have a clear plan, I just started behind him and he saw me but he continued to push. So thanks a lot to Pecco, who helped me improve my lap time."

Rossi's best lap behind Bagnaia in FP3 had been just 0.296s from the top, in a session that saw the entire field covered by just 0.966s.

The pair then began qualifying together, but Rossi's hopes of another tow ended when he ran wide at Turn 1 while trying to stick close to the Ducati.

Rossi was again shadowing Bagnaia as he exited the pits for his last MotoGP qualifying run. More cautious into Turn 1, Rossi struggled to stay in the wheeltracks of the Ducati but what would be his best lap time briefly moved him to seventh, before others improved.

The 42-year-old's speed through the third sector was just 0.085s slower than Bagnaia. The Ducati ace fell at the end of the session, but by then Rossi had used the best of his tyres.

"No, for me it was over because [by then] because for me the good lap is the first lap with the rear tyre. Already on the second lap I lose something. I could do a little bit better I think, but this '30.7 is my potential," said Rossi.

The Italian lapped 0.810s from Pramac Ducati pole man Jorge Martin, but was only 0.126s behind new world champion and fastest Yamaha rider Fabio Quartararo, in eighth. Quartararo's team-mate Franco Morbidelli, another VR46 rider, will start just behind Rossi.

"For me and for us it was a good Saturday, very positive from this morning because already in FP3 I improved the feeling with the bike, the tyres and the setting. At the end I was able to stay in the top ten and to go directly to Qualifying 2.

"This changed everything. And also in the afternoon I was not so bad in FP4. We tried some different tyres. After, in qualifying, I was able to improve my lap time to a '30.7 and stay in the top ten another time, very close to the first Yamaha.

"This is a great feeling for me and for the team in my last race.

"I think that apart from the emotional moment for me it's very important to try to make a good weekend, a good result and I will start in the top ten. So it was a good Saturday."

Rossi, who has a best result of eighth so far this season, will be starting his 432nd grand prix at Valencia.