Bagnaia led from start to finish but came under huge pressure from Quartararo in the final few laps at Ducati's local track of Misano, where the rain that was forecast never arrived.
The Italian held his nerve to secure another victory from pole a week after claiming his maiden MotoGP™ win in Aragon.
Bagnaia's triumph left him 48 points behind Yamaha's championship leader Quartararo, who had to settle for second spot following a late charge after starting in third.
Rookie Enea Bastianini produced a sensational ride to get himself on the podium for the first time, having been way back in 11th on the grid, while Marc Marquez took fourth ahead of Jack Miller and Joan Mir.
Bagnaia got off to a flyer and his team-mate Miller retained second spot off the grid, while Jorge Martin spun off early on at Turn 14 but picked himself up to continue.
Marquez gained a couple of early places and Quartararo flashed past Miller to move into second spot, with Bagnaia extending his advantage out in front.
Bastianini stormed past Marquez into fourth and Martin retired with 16 laps to go before Alex Rins crashed out.
Bagnaia looked comfortable but Quartararo started to close significantly with the laps running out, with the Frenchman scenting a dramatic victory.
The ice-cool Bagnaia was not to be denied, though, and his compatriot secured a magnificent third place after overtaking Miller with nine laps remaining.
- Francesco Bagnaia (Ducati)
- Fabio Quartararo (Monster Energy Yamaha) +0.364s
- Enea Bastianini (Avintia) +4.789s
- Marc Marquez (Repsol Honda) +10.245s
- Jack Miller (Ducati) +10.469s
- Joan Mir (Suzuki Ecstar) +10.325s
- Pol Espargaro (Repsol Honda) +13.234s
- Aleix Espargaro (Aprilia Racing) +15.698s
- Brad Binder (Red Bull KTM) +16.129s
- Takaaki Nakagami (LCR Honda) +18.519s
- Fabio Quartararo (Monster Energy Yamaha) 234
- Francesco Bagnaia (Ducati) 186
- Joan Mir (Suzuki Ecstar) 167
- Johann Zarco (Pramac Racing) 141
- Jack Miller (Ducati) 140
- Monster Energy Yamaha 329
- Ducati 326
- Suzuki Ecstar 235
- Pramac Racing 216
- Red Bull KTM 211