Espargaro (Pons Kalex) had led into the final lap, but Marquez (Monlau Suter) made his move at Quercia to seize the initiative.
Espargaro responded instantly, only to see Marquez come back again through Tremonto.
Still the pair were not done, with Espargaro attacking once more down the back straight. He stole ahead, but Marquez kept his cool, moved to the inside through Carro and forced Espargaro slightly wide, earning enough momentum to cross the line 0.3s ahead of his title rival.
As a result, Marquez now leads the championship by 53 points.
The last-lap fight came after a relatively quiet opening to a race which was interrupted when, three laps in, Gino Rea's engine blew and laid down a film of oil in the final turns, leading to a lengthy red flag period.
Speed Master Speed Up's Andrea Iannone - bidding to win both his home soil races - had already passed Marquez for the lead and therefore inherited pole for the restart, an advantage he held for the majority of the 14 remaining laps.
He was unable to respond once Marquez and Espargaro upped their pace however, and had to settle for the final step of the podium.
Marc VDS duo Mika Kallio and Scott Redding finished fourth and seventh, sandwiching Esteve Rabat (Pons Kalex) and Dominique Aegerter (Technomag-CIP Suter).