Quartararo had led every lap of the first 26, but was denied a maiden win by Marquez, who had to pass the Frenchman twice on the final tour.
Poleman Maverick Vinales had maintained the lead off the line, and the Petronas duo of Quartararo and Franco Morbidelli briefly made it a Yamaha 1-2-3.
Marquez, who had started fifth after his qualifying run-in with Valentino Rossi, was up to fourth on the opening lap, and picked off Morbidelli at Turn 8 on the second tour to set out after the leaders.
As the championship leader kept Vinales and Quartararo in his sights, the latter got a superb run on the former out of Turn 10 and edged ahead entering Curvone to take the lead and immediately begin breaking away.
By the time Marquez pulled off an aggressive move on Vinales down the inside of Turn 10 on the following lap, Quartararo was already almost a second up the road - but the Honda man needed just a couple of laps to arrive right behind the rookie.
Yet Quartararo held firm in the lead, the gap between him and Marquez oscillating between one and four tenths for much of the race as the Frenchman soaked up the pressure.
Marquez, however, ramped up his efforts as the contest entered its final three laps, and finally drew alongside Quartararo at the end of the penultimate lap to take the lead into Turn 1.
Quartararo responded with a brave dive down the inside of Turn 4, but Marquez's Honda outdragged the Yamaha on the run up to Quercia, and he was late on the brakes to consolidate the lead.
And while Quartararo kept Marquez in his sights through the next few corners, he had to release the throttle to avoid clattering into the Honda at Turn 14, and was forced to settle for second place.
The victory leaves Marquez with a 93-point lead in the championship, with 150 up for grabs in the remaining six races.
Vinales had slipped to two seconds behind the leading duo after losing first place, and while he kept pace with the pair from the on, he could only close the gap to the race winner down to 1.6 seconds by the finish.
His fellow works rider Valentino Rossi and Quartararo's Petronas teammate Franco Morbidelli made it four Yamahas in the top five.
Having cleared the KTM of Pol Espargaro, Rossi spent several laps behind Morbidelli before lunging down the inside of his protege at Quercia - and while he ran out wide to allow Morbidelli back through, he then got the move done at Turn 14, going on to finish a tenth clear.
Andrea Dovizioso salvaged sixth place in a difficult race for Ducati, while Espargaro - who had started on the front row - was shuffled down to an eventual seventh place.
Suzuki's Joan Mir, making his return from injury, was eighth ahead of the Pramac Ducati of Jack Miller and the works Ducati of Danilo Petrucci.
Aleix Espargaro finished 12th as the sole Aprilia, with Andrea Iannone absent through injury, while Marquez's Repsol Honda squadmate Jorge Lorenzo took 14th.
Suzuki rider Alex Rins ran sixth in the early going, but his progress was stalled when he straightlined Turn 2 in pursuit of Espargaro.
Back on Espargaro's tail, he overtook the KTM rider, only to immediately receive a long-lap penalty and then crashing at Turn 4 before he could serve it.
Also crashing at Turn 4 were Francesco Bagnaia (Pramac) and Miguel Oliveira (Tech 3), while LCR pair Takaaki Nakagami and Cal Crutchlow and Ducati wildcard Michele Pirro likewise crashed - the latter running 10th ahead of Petrucci when he hit the deck.
|View full results|