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 outmuscled 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.