Jorge Lorenzo won his first race of the MotoGP season at a rain-affected Aragon Grand Prix after championship leader Marc Marquez crashed.
Lorenzo and Marquez were fighting for the lead when it began to rain in the closing stages in Spain.
Lorenzo opted to pit and change his set-up while Marquez and title rival Dani Pedrosa chose to stay out, and both fell before remounting to finish.
Aleix Espargaro was second with Britain's Cal Crutchlow in third.
It was Yamaha rider Lorenzo's first victory since the last race of 2013.
"It has been a long time without a win and to get it in these conditions is incredible," said Lorenzo. "I was concentrating on not crashing and was ready to finish third.
"It was a crazy race. I wasn't happy when it started to rain as the Hondas were starting to get away from me. I wasn't comfortable at all. Then it started raining more and I decided to go for it."
|MotoGP championship standings|
|Marc Marquez (Spa) Repsol Honda||292 points|
|Dani Pedrosa (Spa) Repsol Honda||217 points|
|Valentino Rossi (Ita) Yamaha||214 points|
|Jorge Lorenzo (Spa) Yamaha||202 points|
|Andrea Dovizioso (Ita) Ducati||142 points|
Spaniard Marquez, who had taken the 20th pole position of his career on Saturday with a record qualifying time, finished 13th, one place ahead of compatriot Pedrosa, which means he extends his overall lead in the championship standings by a point.
Marquez said the most important thing was finishing ahead of Pedrosa. "It was all or nothing. I saw there were four laps to go and as I would have lost a lot of time I decided to stay out to see if I could finish the race," the championship leader said. "I am not experienced in these conditions, it has never happened to me before."
Seven-time world champion Valentino Rossi, who won his first MotoGP in 15 months with victory at his home track in San Marino two weeks ago, crashed out early in the race before the rain started.
The Italian was carried off the circuit on a stretcher but was later able to stand and did not appear seriously hurt.
Others fallers were Italians Andrea Dovizioso and early leader Andrea Iannone.
The next race is in Motegi, Japan, on Sunday, 12 October.
San Marino MotoGP result:
1. Jorge Lorenzo (Spa) Yamaha 44:20.406secs
2. Aleix Espargaro (Spain) Yamaha +10.295
3. Cal Crutchlow (Britain) Ducati +10.312
4. Stefan Bradl (Germany) Honda +11.718
5. Bradley Smith (Britain) Yamaha +29.483
6. Pol Espargaro (Spain) Yamaha +29.686
7. Alvaro Bautista (Spain) Honda +29.763
8. Hiroshi Aoyama (Japan) Honda +37.841
9. Nicky Hayden (U.S.) Honda +42.957
10. Scott Redding (Britain) Honda +53.937