Portuguese rider Miguel Oliveira held off a late challenge from Frenchman Johann Zarco to win the Catalonia MotoGP on Sunday.
Australian Jack Miller took third after championship leader Fabio Quartararo was hit with a three-second penalty.
"Everything was so hard: tyre management, keeping cool when Fabio was putting the pressure on me for so many laps," said Oliveira, who delivered a series of metronomic laps on his KTM.
"I was not superfast but I was constant and it paid off."
Both Quartararo and Miller led briefly, but had problems.
Miller said he "felt mega" but had trouble with tyres overheating.
"Miguel and Fabio were able to be very consistent, whereas I made a few too many little mistakes," said the Australian.
Frenchman Quartararo was penalised for going way off the track on his Yamaha at the chicane four laps from the end.
The rider from Nice finished the race barechested and without a piece of required safety gear, after unzipping his jacket and discarding his chest protector.
Quartararo remains top of the rider standings but Zarco, of the Ducati satellite team Pramac, cut the gap to 17 points.
Miller climbed to third, overtaking his factory Ducati team-mate, Italian Francesco Bagnaia, who was seventh.
Zarco, who has still to win in the MotoGP class, moved through the pack late in the race.
"I could even think about the victory, but Miguel did an amazing job," said Zarco. "I was not close enough to attack him."
The race was the first this season to allow a substantial number of fans, with a crowd of 24,000, 20 percent of capacity.
After crossing the line, Oliveira ran to the stands.
"Everything has been amazing this weekend with the public back," he said.
- 'The energy is amazing' -
Oliveira collected his third MotoGP victory after winning twice last season when the stands were empty.
"I got two without any crowd and just to be able to run to the crowd and get a flag and feel the energy is amazing."
The fans cheered him enthusiastically after a disappointing weekend for local riders.
Marc Marquez (Honda) and both Espargaro brothers, Pol (Honda) and Aleix (Aprilla) crashed. A fourth Catalan, Alex Rins, broke a wrist in a bicycling accident before the race and did not start.
Iker Lecuona (KTM), who is from down the coast in Valencia, also failed to finish on Sunday.
Title holder Joan Mir (Suzuki) was top Spanish finisher in fifth. Maverick Vinales (Yamaha0 was the only one of the five Catalan starters to complete the race, coming sixth.
In Moto2, team-mates Remy Gardner and Raul Fernandez dominated the race just as they are dominating the standings.
Australian Gardner spent half the race stalking young Spaniard Fernandez.
"I said to myself, 'right two laps from the end I'm going to pass him and just go for it'. I saw the opportunity on turn one and I thought 'let's do it' and put the hammer down," said Gardner.
In Moto3, Spaniard Sergio Garcia came from 19th on the grid to win.
The 18-year-old GasGas rider edged compatriot Jeremy Alcoba on a Honda by 0.015sec in a breathless finish.
The first 10 finishers were separated by barely a second.
"It was a really crazy race," Garcia said after his second win of the year.
Garcia moved up to second in the standings, 39 points behind another Spanish teenager, Pedro Acosta who finished seventh.
On the podiums, riders wore T-shirts in tribute to Swiss rider Jason Dupasquier, who died at the age of 19 last week after an accident during the Moto3 Italian Grand Prix practice in Mugello, Italy.