Reigning world champion Bagnaia looked set to cruise to a first sprint win since the Austrian Grand Prix last year having led by just under a second at the start of lap nine.
But the Ducati rider made a mistake under braking and flew off track at Turn 1, dropping to fourth and releasing Vinales into a slender lead over Pramac’s Jorge Martin.
Martin hounded Vinales over the final few laps, but the Aprilia racer put in a determined ride despite suffering from gastroenteritis to pull a gap to the Pramac Ducati on the last tour.
Vinales got to the chequered flag 1.039s clear of the field to score his first win in Aprilia colours and first since the Qatar GP in 2021 when he was a Yamaha rider.
Marc Marquez scythed past Martin at Turn 5 on the last lap with a hard pass to finish second and score his first podium on the Gresini Ducati.
Bagnaia was fourth after his mistake but still holds a slender two-point lead in the championship.
KTM’s Jack Miller got the holeshot off the line from fifth on the grid as Bagnaia carved his way through from fourth to second by way of an overtake on Vinales at Turn 3.
Poleman Bastianini on the sister factory Ducati dropped to fourth off the line, while Martin slumped to sixth from third on the grid.
Marc Marquez, Gresini Racing
Photo by: Gold and Goose / Motorsport Images
Marquez pushed Bastianini back to fifth at Turn 13 on lap one when the factory Ducati rider ran slightly wide, while Martin soon followed suit.
On lap two, Marquez threw his Ducati GP23 up the inside of Vinales at Turn 11 and made contact with the Aprilia rider on the exit, before slamming the door shut in the #12’s face to snatch third on the change of direction into Turn 12.
At the final corner, Bagnaia took advantage of Miller running slightly wide through the long downhill right-hander to lead the sprint at the start of the third tour.
Marquez pushed Miller to third on lap three at Turn 11, with Martin also shuffling the KTM rider further down the order.
A moment for Marquez on lap five at Turn 5 let Vinales back into second, while Martin would push the Gresini rider off the podium a tour later.
While all this was going on, Bagnaia had swelled his lead to a second and kept it around the 0.8s gap until he got out of shape on the brakes into Turn 1 on lap 12 and dropped to fourth.
Vinales kept Martin at bay despite the Pramac rider’s best efforts, from Marquez and Martin.
Bagnaia was 3.033s off the podium in fourth ahead of Miller and Bastianini, while Tech3 GasGas rookie Pedro Acosta finished seventh ahead of Aprilia’s Aleix Espargaro and Yamaha’s Fabio Quartararo.
Quartararo’s team-mate Alex Rins crashed out on lap three, with KTM’s Brad Binder and VR46 Ducati rider Fabio Di Giannantonio suffering separate falls a tour later, as Johann Zarco also fell off his LCR Honda.