Dovizioso, using the latest-spec aero fairing on his Ducati, leapt from eighth to the top of the timesheets with a flying lap completed after the chequered flag fell, posting a 1m54.689s to oust Marc Marquez from the top of the leaderboard.
It marks the Italian rider's first pole of the season, as well as his first since the 2016 Malaysian GP.
Grand Prix Valencia
'An inspiration for me' - Federer leads Rossi tributes after final race
Rossi followed immediately behind Dovizioso to secure his place in the middle of the front row with a time 0.267s slower than his compatriot, which demoted Marquez to third.
It was the other works Ducati rider Jorge Lorenzo, also running the new fairing, who had led the opening runs - a 1m55.059s lap put him nearly half a second up on the opposition, led by LCR Honda's Cal Crutchlow.
But Lorenzo could not make a significant improvement on his second run, posting a 1m55.038s that was soon beaten by Marquez, and then by both Dovizioso and Rossi.
Joining Lorenzo on the second row are Crutchlow and the lead Pramac Ducati rider Danilo Petrucci.
Johann Zarco was seventh on the Tech3 Yamaha ahead of Suzuki pair Alex Rins and Andrea Iannone, who briefly went second fastest only to then tumble down the order, and Honda's Dani Pedrosa.
Tito Rabat (Avintia Ducati) and Maverick Vinales completed the Q2 order, with the latter posting a time three tenths slower than the one that had allowed him to progress out of Q1.
Vinales was the highest-profile runner in Q1 and duly commanded much of the session, taking an early lead in the opening runs ahead of the Alvaro Bautista.
The Yamaha rider improved again in the latter part of the session to put his Q2 progression beyond doubt, but Bautista found himself ousted by Rins before falling at Turn 12 trying to better his time.
Bautista was therefore demoted to fourth, with Franco Morbidelli ending up the quickest of those to miss the Q2 cut.
The Marc VDS Honda rider will head up the fifth row, ahead of Bautista and the lead KTM rider Bradley Smith.
Pramac Ducati's Jack Miller also crashed early-on at Turn 9, putting him down in 17th on the grid behind the second Tech3 Yamaha of Hafizh Syahrin.
Honda wildcard Stefan Bradl will start one place behind in 18th, while third Suzuki rider Sylvain Guintoli will line up 21st.
Aprilia endured a nightmare session as Scott Redding crashed at Turn 3 and Aleix Espargaro appeared to suffer a mechanical failure.
Espargaro will start 24th and Redding 25th.
Rossi announces decision to retire at end of season
MotoGP star Jason Dupasquier dies after crash
Share this article