Quartararo’s points lead stood at 10 points ahead of this round, but his worst result of the season and a third for Mir means he is now six points behind the Spaniard, with 15 points covering the top four.
Franco Morbidelli got the holeshot into the first corner off the line, but the Petronas SRT rider ran wide and allowed Maverick Vinales and Quartararo to move through.
Vinales used the early grip advantage of his soft front tyre to put seven tenths of daylight between himself and Quartararo, while Rins had leaped from 10th to fourth.
Quartararo resisted an attack from his teammate Morbidelli at Turn 12 on the opening lap, with the latter’s pace quickly dropping off and Rins soon finding a way through.
The lead gap reduced slightly to half a second, but Rins’ charge continued and he capitalised when the Frenchman ran wide at the last corner at the end of lap five to take second.
Quartararo repeatedly ran wide at the final two corners and his pace deteriorated significantly over the next 10 tours, the Petronas rider falling out of the points in 17th by lap 15.
Rins took the lead from Vinales at the final corner on lap eight, with the Yamaha rider falling into the clutches of the sister Suzuki of Mir after a brief tussle five tours later.
The lead for Rins stood at 1.1 seconds following this, but Mir was able to close the gap with Marquez in tow, the Honda rider having carved his way through from 11th on the grid.
Rins’ advantage came down to just over six tenths on lap 15, but Mir’s victory challenge would come to nought and he was powerless to stop Marquez coming through on lap 18.
Marquez, having taken his debut podium in last week’s wet Le Mans race, said on Saturday the rostrum was not a “real target”.
But once clear of Mir, he quickly got onto Rins’ tail and piled on the pressure, regrouping instantly despite a massive moment as he applied the throttle at the last corner on the 21st tour.
Rins did not make a mistake across the final lap and had enough in hand to beat Marquez by 0.263 seconds at the chequered flag to become the eighth different winner in 2020.
Mir’s pace dropped in the final lap but not enough to allow Vinales back onto the podium, with the Suzuki rider now leading the standings for the first time by six points.
Vinales is just 12 points off the championship lead after finishing fourth, with Takaaki Nakagami completing the top five on his LCR Honda ahead of Morbidelli.
Andrea Dovizioso recovered from 13th on the grid to seventh, with Quartararo’s misery meaning the Ducati rider is now only 15 points off the standings lead.
Cal Crutchlow on the sister LCR bike trailed Dovizioso home after a shocking start from third, with Pramac’s Jack Miller heading Avintia’s Johann Zarco to round out the top 10.
The KTMs were headed by Brad Binder in 11th ahead of Pol Espargaro, with Aleix Espargaro on the Aprilia, Tech 3’s Iker Lecuona and Danilo Petrucci (Ducati) taking the last points.
Quartararo could do no more than 18th at the chequered flag, with only Bradley Smith on the Aprilia and Avintia’s Tito Rabat behind him after Francesco Bagnaia (Pramac) crashed early on.