The Ducati rider and his Spanish rival, aiming to win on his fifth straight appearance at the track having not raced there in 2020, exchanged position several times over the course of a pulsating finish.
But the Italian, who started on pole, put on a masterclass to beat Repsol Honda rider Marquez in his own backyard to clinch an unbelievable victory and move up to second in the riders' standings.
Bagnaia finished down in 14th last time out at the British Grand Prix for his worst result in two years but he and Marquez stole a march on the chasing pack this time around.
It has been a largely disappointing season for the legendary Marquez, who missed almost the entirety of 2020 through injury, yet there were signs of his best in a thrilling chase.
Marquez made his first move at Turn 5 with three laps to go, only to go wide and allow Bagnaia to reclaim the lead.
That theme continued for the rest of the race as Marquez made several passes and on each occasion giving it back, until finally he went off track at Turn 12 allowing Bagnaia to finally claim a win in the premier class.
- Francesco Bagnaia (Ducati)
- Marc Marquez (Repsol Honda) +0.673s
- Joan Mir (Suzuki Ecstar) +3.911s
- Aleix Espargaro (Aprilia Racing) +9.269s
- Jack Miller (Ducati) +11.928s
- Enea Bastianini (Avintia) +13.757s
- Brad Binder (Red Bull KTM) +14.064s
- Fabio Quartararo (Monster Energy Yamaha) +16.575s
- Jorge Martin (Pramac Racing) +16.615s
- Takaaki Nakagami (LCR Honda) +16.904s
- Fabio Quartararo (Monster Energy Yamaha) 214
- Francesco Bagnaia (Ducati) 161
- Joan Mir (Suzuki Ecstar) 157
- Johann Zarco (Pramac Racing) 137
- Jack Miller (Ducati) 129
- Monster Energy Yamaha 309
- Ducati 290
- Suzuki Ecstar 225
- Pramac Racing 212
- Red Bull KTM 204