Marc Marquez failed to win a race for just the second time this season as Valentino Rossi claimed the San Marino MotoGP.
The Repsol Honda rider had won 11 of the opening 12 races of the season to open up an 89-point lead at the head of the championship, but an error on the 10th lap cost him dearly on Sunday as he picked up a single point in 15th.
Rossi led from the early stages after overtaking Yamaha team-mate Jorge Lorenzo and Marquez's crash gave him a comfortable cushion at the front.
The result marks the Italian's first victory since he triumphed at Assen in 2013, and sees him climb to within a point of second-placed Dani Pedrosa in the championship. Pedrosa finished third in Sunday's race.
Lorenzo, who eventually came home in second, made a great start from pole and led into turn one followed by team-mate Rossi, while Marquez also passed Andrea Iannone to go third.
The front three made an early break and Marquez was proving a nuisance for the two Yamahas as he chased Mick Doohan's 1997 record of 12 wins in a single MotoGP campaign.
Marquez and Rossi tussled for second place during the opening three laps, but the latter spotted an opportunity to take the lead and made it stick on lap four.
Marquez soon followed suit in passing Lorenzo at turn 14 and opened up a gap of half a second over his compatriot.
Rossi was coming under increasing pressure from Marquez, who did well to keep his bike upright on lap eight when he misjudged turn 12.
However, Marquez's desperate quest for the lead took a turn for the worse on lap 10. The Spaniard lost his front end and had to rely on the help of four track marshalls to get going again.
The incident saw Marquez slip to 20th position and his progress in wading back through the field proved too slow.
Rossi was the main beneficiary as he capitalised on a lack of serious challengers to widen the gap between himself and second place.
Lorenzo inititally looked capable of potentially reeling Rossi in, but the Italian responded well to keep his lead at just under three seconds.
Andrea Dovizioso (Ducati), Iannone (Pramac Racing) and Pol Espargaro (Monster Yamaha Tech 3) finished fourth, fifth and sixth respectively.