Defending champion Jorge Lorenzo extended his lead in the MotoGP standings to 10 points after a dramatic victory at the Italian Grand Prix.
The 29-year-old Spaniard, who leaves Yamaha at the end of the season to join Ducati, held off compatriot Marc Marquez by 0.019 seconds in Mugello.
Local hero Valentino Rossi, who was on pole, encountered a mechanical problem on lap eight and soon retired.
The Italian, 37, is now 37 points behind Lorenzo with 12 races remaining.
Lorenzo took the lead from Rossi at the first corner, and to the despair of the home crowd the nine-time world champion bowed out midway through the 23-lap race with smoke billowing from his bike.
Marquez, the 2013 and 2014 champion who remains second in this year's standings, took the lead on the final lap, before Lorenzo seized the victory metres from the chequered flag in the closest finish of the season to date.
The Spaniard admitted his third victory of the season was a surprise and added: "I used up a lot of energy to stay in the lead during the race and I thought that Marquez had more energy when he passed me, so I just wanted to stay in second place and take the points.
"I tried a crazy move, and my bike was quite fast, so I could take the win off Marquez and I won this unexpected victory."
Andrea Iannone of Italy finished a distant third but set a new MotoGP top speed record of 354.9kmh (220.5mph).
In Moto2 Britain's Sam Lowes leads by two points after finishing third behind Johann Zarco of France and Italian Lorenzo Baldassarri.
South African Brad Binder consolidated his Moto3 lead by recording a third successive win.
Italian MotoGP result:
1. Jorge Lorenzo (Spain) Yamaha 41 minutes, 36.535 seconds
2. Marc Marquez (Spain) Honda 41:36.554
3. Andrea Iannone (Italy) Ducati 41:41.277
4. Dani Pedrosa (Spain) Honda 41:41.445
5. Andrea Dovizioso (Italy) Ducati 41:42.791
6. Maverick Vinales (Spain) Suzuki 41:45.205
7. Bradley Smith (Britain) Yamaha 41:49.875
8. Danilo Petrucci (Italy) Ducati 41:51.133
9. Aleix Espargaro (Spain) Suzuki 41:55.178
10. Michele Pirro (Italy) Ducati 41:58.833
11. Cal Crutchlow (Britain) Honda 42:04.471
Overall standings (after race 6 of 18):
1. Jorge Lorenzo (Spain) Yamaha 115 points
2. Marc Marquez (Spain) Honda 105
3. Valentino Rossi (Italy) Yamaha 78
4. Dani Pedrosa (Spain) Honda 66
5. Maverick Vinales (Spain) Suzuki 59
6. Aleix Espargaro (Spain) Suzuki 49
7. Pol Espargaro (Spain) Yamaha 48
8. Hector Barbera (Spain) Ducati 43
9. Andrea Iannone (Italy) Ducati 41
10. Eugene Laverty (Ireland) Ducati 36
12. Bradley Smith (Britain) Yamaha 29