Casey Stoner held off a determined challenge from home favourite Jorge Lorenzo to win the Spanish MotoGP.
The reigning champion made a great start from fifth on the grid in Jerez to take the lead by the end of lap two.
The Australian was not able to pull away though and Lorenzo closed in as both riders struggled with tyre wear.
But Stoner fought to take his first win of the year, with Dani Pedrosa third and British rider Cal Crutchlow fourth on his Tech 3 Yamaha.
Crutchlow excelled again on his way to a second fourth place in two races this season, and he finished the race only 2.4 seconds behind Stoner, who in six previous attempts had never won at Jerez.
On a weekend plagued by wet weather, the whole race stayed dry as Stoner took his 34th MotoGP win.
Stoner revealed after the race that he was again struggling with the arm pump problem which cost him victory in the season opener at Qatar earlier this month.
He told BBC Sport: "The tyres were spinning up a bit in the closing laps but it was not a big problem - it was my arms again.
"Conditions were tricky and that was probably the greatest race I've ever done.
"I made a terrible start and got boxed in but somehow fought through to take the lead.
"Then I felt the arm pump coming in and thought 'oh no'.
"So I just gave it everything and when I saw two laps to go it suddenly felt better. It must be adrenaline."
Spain's Pedrosa got ahead of pole sitter Lorenzo to lead into turn one, with Crutchlow moving up to third, but Stoner soon made a bold move to sweep past Lorenzo and Repsol Honda team-mate Pedrosa to take the lead.
Stoner was looking comfortable but ran wide with 10 laps to go as Lorenzo closed in, only for the Yamaha rider to make a mistake of his own as Stoner hung on.
"I tried to win in front of my people but today Stoner was too fast," Lorenzo told BBC Sport.
"The front tyre was destroyed as well. But I did my best."
Earlier, Romano Fenati won a Moto3 race packed with crashes ahead of Luis Salom and Sandro Cortese
British rider Scott Redding was leading for much of the Moto2 race before rain started to fall and the race was red flagged on lap 19 of 26.
Pol Espargaro was given the win ahead of Marc Marquez and Thomas Luthi, with Redding finishing fourth.
Spanish MotoGP results:
1. Casey Stoner (Aus) Repsol Honda 45:33.897
2. Jorge Lorenzo (Spa) Yamaha 45:34.844
3. Dani Pedrosa (Spa) Repsol Honda 45:35.960
4. Cal Crutchlow (GB) Tech3 Yamaha 45:36362
5. Andrea Dovizioso (Ita) Tech3 Yamaha 45:51.997
6. Alvaro Bautista (Spa) Gresini Honda 45:55.292
7. Stefan Bradl (Ger) LCR Honda 46:02.534
8. Nicky Hayden (US) Ducati 46:02.766
9. Valentino Rossi (Ita) Ducati 46:08.749
10. Hector Barbera (Spa) Pramac Ducati 46:09.000