Jorge Lorenzo delivered Yamaha its first MotoGP win since June in his final race for the Japanese manufacturer at Valencia, hanging on against a charging Marc Marquez in the closing stages.
On his final outing for the team with which he has spent his entire premier class career so far, Lorenzo converted pole position into an early lead, and immediately distanced himself from the chasing pack.
Breaking the race lap record on the second tour, Lorenzo made the best possible use of the clear track ahead to break free from his pursuers, led by the fast-starting Ducati of Andrea Iannone.
By the time Valentino Rossi had cleared Iannone for second, Lorenzo was already 2.5 seconds clear of his teammate - a gap which nearly doubled in the space of five laps as Rossi continued his scrap with Iannone, with Marc Marquez and Maverick Vinales keeping close company.
With some 10 laps remaining, Marquez broke clear of Rossi and Iannone to take second, and the Repsol Honda man began to erode Lorenzo's advantage out front.
In four laps, Marquez - running with the hard front tyre - had reduced the gap from 4.5s to 2.7s, as Lorenzo appeared to struggle with graining on his medium-compound front Michelin.
At the start of the final lap, Lorenzo had 1.7s in hand over Marquez, a gap big enough to allow him to score a third victory of the year, and a 44th of his career, by 1.185s.
Behind, Iannone and Rossi continued their frenzied battle for what became the bottom step of the podium, with the Ducati rider ultimately coming out top to take his first podium finish since winning August's Austrian race on his final race for the Italian marque.
Rossi came home fourth on the second Yamaha, followed by a fading Vinales, the Spanish rider taking fifth in his final race for Suzuki.
Some way behind, Andrea Dovizioso, who had run at the tail of the battle for second in the first half of the race, was pipped to the line by Pol Espargaro's Tech 3 Yamaha for sixth place by 0.039s
Aleix Espargaro brought home the second Suzuki just behind the pair in eighth, followed by Bradley Smith's Tech 3 Yamaha and Alvaro Bautista's Aprilia.
Honda riders Dani Pedrosa and Cal Crutchlow both crashed out, the former going down at Turn 2 in the early stages and the latter exiting at mid-distance with a fall at Turn 14.
Yonny Hernandez (Aspar Ducati) also ended his premier class career with a crash-induced DNF.
KTM's Mika Kallio was the only other non-finisher, pulling into the pits with an electronics problem with 10 laps remaining on the Austrian marque's MotoGP race debut.