Spaniard Lorenzo took the lead from pole-sitter Rossi at the first corner, but nine-time world champion Rossi bowed out early after his bike failed him when he was looking primed to make a pass.
Instead it was down to Marquez to pressure world champion Lorenzo, and he took the lead from his compatriot on the final lap, only to see the Yamaha man steal the victory metres from the finish.
After a week in which riders have been swapping teams for next season, outgoing Ducati rider Andrea Iannone had a horrific start for the home team.
He and team-mate Andrea Dovizioso had only finished two races each going into this week, and neither ever looked like challenging for the lead at the Mugello Circuit.
That meant that the home crowd had their hopes pinned on 37-year-old Rossi, but those went up in smoke with 13 of 23 laps still to go.
Championship leader Lorenzo made the most of the opportunity to claim his third win of the season and second in a row, to extend his advantage in the riders’ standings over Honda’s Marquez to 10 points.
“The pace was not very fast, so I couldn’t escape like I wanted to,” Lorenzo said.
“I used up a lot of energy to stay in the lead during the race and I thought that Marquez had more energy when he passed me, so I just wanted to stay in second place and take the points.
“I tried a crazy move, and my bike was quite fast, so I could take the win off Marquez and I won this unexpected victory.”
Iannone, who confirmed that he will be joining Suzuki next year after Ducati chose Dovizioso to partner the incoming Lorenzo for next season, battled back well to take a podium finish from what had been a very encouraging week.
“I am a bit disappointed. The clutch slipped and the bike started with a big wheelie,” Iannone said.
“The podium in Italy is very good but I had the potential to fight for the victory.”
Earlier at Mugello, French reigning champion Johann Zarco won the Moto2 category.
He finished ahead of Italian Lorenzo Baldassarri and Briton Sam Lowes, the latter taking over at the top of the overall standings from Spanish rival Alex Rins.
South African Brad Binder consolidated his Moto3 lead by reeling off a third successive win.