Just 0.088 seconds separated the pair at the chequered flag, with Lorenzo eventually prevailing when he dipped down to a 1m29.167s. The pair had taken turns at the top before Lorenzo's late effort.
Marquez can mathematically wrap up a rookie championship this weekend in Australia, although he needs to outscore Lorenzo by at least eight points.
The two championship rivals were in a class of their own throughout, and were set to finish nearly one second clear of the entire field until several riders improved in the final minutes.
Chief among them was Gresini Honda rider Alvaro Bautista, who produced a 1m29.831s - still some six tenths down on Lorenzo - to steal into third ahead of works counterpart and Sepang winner Dani Pedrosa.
Valentino Rossi meanwhile edged Tech 3 Yamaha's Cal Crutchlow in the fight for fifth, with the Briton in turn less than a quarter of a second clear of team-mate Bradley Smith.
Nicky Hayden, who will join the Aspar squad and ride Honda's production racer next season, was eighth fastest.
Randy de Puniet claimed top CRT honours in ninth, finishing fractions ahead of Ducati's Andrea Dovizioso and Pramac's Andrea Iannone.
Stefan Bradl, riding less than a week after fracturing and then having surgery on his right ankle, managed 11 laps and wound up 20th overall.
He was passed fit to start first practice at Phillip Island, but will need to undergo further medical checks in order to continue competing.