Valentino Rossi charged back from a poor start at Sepang to take his first race win since returning following his injury lay-off, as his Yamaha team-mate Jorge Lorenzo superseded the Italian legend as world champion by taking third behind Andrea Dovizioso.
Despite needing only a ninth place to win the title, Lorenzo looked like he was up for a fight for victory as he led at the start and fended off big pressure from Honda rider Dovizioso.
Ducati's Casey Stoner was with them at first too - but not for long, as he crashed out at the final corner before the opening lap was even complete.
At that stage, Rossi was nowhere near the lead fight, as an appalling start had dropped him right back to 11th from his disappointing sixth on the grid.
But his fight-back was breathtaking. Up to sixth within two laps, he was third by lap four - and soon setting fastest lap after fastest lap as he chased down Lorenzo and Dovizioso.
On lap nine Dovizioso finally managed to take the lead from Lorenzo into the first corner, with Rossi also passing his team-mate a lap later.
It only took one more lap for Rossi to catch and pass Dovizioso too, diving down the inside at Turn 9 just as he had to so many riders earlier in the race.
Dovizioso never let him escape - and even thrust his Honda back in front for half a lap five from the end - but Rossi used his Turn 9 move again to reclaim the lead, and then held his countryman at bay all the way to the chequered flag.
The win ended Rossi's longest-ever MotoGP victory drought, as he had not triumphed since the Qatar season opener six months ago.
His reign as world champion ended though, as Lorenzo cruised to third place and claimed more than enough points to win his first title.
Marco Simoncelli held fourth for Gresini Honda for much of the race, but his pace faded in the second half and he was reeled in by Ben Spies - who passed him and grabbed fourth for Tech 3 Yamaha.
Simoncelli then got embroiled in a massive battle with former 250cc rival Hiroshi Aoyama (Interwetten Honda), Suzuki's Alvaro Bautista and Ducati's Nicky Hayden, whose race pace could not match the qualifying form that saw him start second.
The quartet diced furiously over the final laps, with Bautista getting through to equal his career-best in fifth, and Hayden picking up sixth as Aoyama and Simoncelli bounced off each other. The Japanese rider still managed his best MotoGP finish yet in seventh, while Simoncelli was left to fend off his team-mate Marco Melandri for eighth, as the elder Italian escaped from an early dice with Randy de Puniet (LCR Honda).
Pos Rider Team Time/Gap 1. Valentino Rossi Yamaha 41m03.448s 2. Andrea Dovizioso Honda + 0.224s 3. Jorge Lorenzo Yamaha + 6.035s 4. Ben Spies Tech 3 Yamaha + 13.676s 5. Alvaro Bautista Suzuki + 15.402s 6. Nicky Hayden Ducati + 18.826s 7. Hiroshi Aoyama Interwetten Honda + 20.218s 8. Marco Simoncelli Gresini Honda + 23.574s 9. Marco Melandri Gresini Honda + 23.964s 10. Randy de Puniet LCR Honda + 31.850s 11. Hector Barbera Aspar Ducati + 38.579s 12. Mika Kallio Pramac Ducati + 38.849s Retirements: Colin Edwards Tech 3 Yamaha 9 laps Aleix Espargaro Pramac Ducati 6 laps Loris Capirossi Suzuki 4 laps Casey Stoner Ducati 0 laps