The 19-year-old Italian's triumph came after one of the fiercest races as the top three crossed the line within four hundredths of a second and the top six inside two tenths.
Bagnaia had qualified tenth, on the fourth row of the grid, but he put his white-liveried Aspar Mahindra racer at the sharp end throughout.
After 99.924 km of the fiercest fighting, the 19-year-old star was ready to claim a virtual photo-finish win in a fairing-banging, paint-swapping brawl through the final chicane.
"In the first lap I overtook I think four or five riders, and in every lap I wanted to stay in first position as I knew that the rain could arrive at any time, and it was really important to stay at the front of the group. In the last two corners I thought it was impossible to get first, but finally I just did it, and it was incredible for me and for Mahindra."
Also Read
Indian automotive and industrial giant Mahindra made a low-key start in grand prix racing in 2011, taking over an existing team in the final year of the old 125cc two-stroke formula. In 2012, with the advent of 250cc four-stroke Moto3 machines, Mahindra embraced full constructor status, with their own machine; and in 2013 launched the all-new MGP3O.
Victory moved Bagnaia up to fourth in the championship, just four points away from third.
Second team rider Jorge Martin withdrew on the first day, as hand injuries sustained three weeks ago at the Catalunya GP had not sufficiently healed. His place was taken by fellow-Spaniard Alberto Arenas (19).