Dani Pedrosa escaped from a ferocious lead fight to take his first MotoGP win since May at Sepang.
The early laps were some of the best of the season as the factory Yamahas and Hondas plus Gresini's Alvaro Bautista formed a five-bike pack jostling for the lead.
It was Lorenzo who led that group, having out-muscled fellow fast-starter Pedrosa through the opening corners.
Pedrosa's Honda repeatedly got a run on Lorenzo's Yamaha on the following laps, but the champion always managed to brake later into the corners.
Finally Pedrosa slipped past down the back straight, with the two bikes brushing at the final corner as he completed the move.
That gave Marquez a run at Lorenzo and began an astonishingly hard-fought battle between them, in which Lorenzo did his utmost to fend off Marquez with some bold repasses.
It took several laps and several near-misses before Marquez finally made it ahead for good.
Pedrosa was only a second in front at that point, but had speed in hand and was able to pull away and win by nearly three seconds.
Marquez left Lorenzo behind as he extended his championship lead with second, while Valentino Rossi completed the top four.
Bautista dropped away from the lead group and became embroiled in a spectacular dice with Cal Crutchlow, only beating the Tech 3 Yamaha on the final lap.
Bradley Smith and Andrea Dovizioso were next up, with CRT leader Aleix Espargaro keeping Pramac Ducati's Yonny Hernandez at arm's length for ninth.
Nicky Hayden retired from seventh with smoke pouring from his Ducati early on.
Results - 20 laps: Pos Rider Team/Bike Time/Gap 1. Dani Pedrosa Honda 40m45.191s 2. Marc Marquez Honda +2.757s 3. Jorge Lorenzo Yamaha +6.669s 4. Valentino Rossi Yamaha +10.351s 5. Alvaro Bautista Gresini Honda +22.149s 6. Cal Crutchlow Tech 3 Yamaha +22.301s 7. Bradley Smith Tech 3 Yamaha +30.864s 8. Andrea Dovizioso Ducati +45.111s 9. Aleix Espargaro Aspar Aprilia +59.264s 10. Yonny Hernandez Pramac Ducati +1m01.417s 11. Hiroshi Aoyama Avintia FTR-Kawasaki +1m03.665s 12. Randy de Puniet Aspar Aprilia +1m14.256s 13. Claudio Corti Forward FTR-Kawasaki +1m21.603s 14. Hector Barbera Avintia FTR-Kawasaki +1m27.976s 15. Colin Edwards Forward FTR-Kawasaki +1m29.442s 16. Danilo Petrucci Ioda-Suter-BMW +1m29.551s 17. Luca Scassa Cardion Aprilia +1m47.930s 18. Bryan Staring Gresini FTR-Honda +1m52.927s Retirements: Michael Laverty PBM Aprilia 12 laps Lukas Pesek Ioda-Suter-BMW 11 laps Nicky Hayden Ducati 8 laps Damian Cudlin PBM-Aprilia 7 laps Andrea Iannone Pramac Ducati 6 laps Stefan Bradl LCR Honda 0 laps