Gresini Honda's Alvaro Bautista lost a position to Rossi on the final lap, with Pramac Ducati's Hector Barbera staying out of trouble on his way to seventh.
Aleix Espargaro (Aspar) and James Ellison
(PBM) led the CRT challenge in eighth and ninth with Cardion AB Ducati's Karel Abraham completing the top ten.
Lorenzo was the only Yamaha rider not to fall, with team-mate Ben Spies the highest profile victim of the conditions, suffering a shoulder injury after highsiding from his Yamaha.
Tech 3 M1 riders Cal Crutchlow and Andrea Dovizioso, LCR Honda's Stefan Bradl and CRT riders Randy de Puniet, Ivan Silva and Roberto Rolfo also crashed.
Spies fell with five laps to go, and the others all within three laps of the red flag, the period when the rain intensified.
Dovizioso, who had got a big slide at the start and almost collected Spies, was closing on Stoner for third place when he slid off. The Italian rejoined and was thus classified 13th and last.
MotoGP now heads straight for the Australian Grand Prix at Phillip Island, the third race in three weekends, where Stoner will be chasing a sixth win in a row on his final home appearance before retirement.
Malaysian Grand Prix:
1. Dani Pedrosa
2. Jorge Lorenzo
3. Casey Stoner
4. Nicky Hayden
5. Valentino Rossi
6. Alvaro Bautista
7. Hector Barbera
8. Aleix Espargaro
9. James Ellison
10. Karel Abraham
11. Danilo Petrucci
12. Michele Pirro
13. Andrea Dovizioso
Randy De Puniet