Dovizioso and Marquez swapped places several times during the final laps of a pulsating race in Buriram
Championship leader Marc Marquez held off title rival Andrea Dovizioso to win a thrilling inaugural Thailand MotoGP.
Polesitter Marquez passed Dovizioso on the final corner to secure his seventh win of the season.
The Spaniard extended his championship lead over Dovizioso to 77 points with four races remaining, and he can clinch a fifth MotoGP title in six years at Motegi in Japan on 21 October.
Maverick Vinales finished third, with Valentino Rossi fourth.
"It was difficult. It is amazing to win after a difficult weekend," said Marquez.
After a tight start to the race in which the top eight riders were covered by less than two seconds at the halfway mark, Dovizioso, Marquez and Rossi began to pull clear inside the final 10 laps.
Vinales was able to close the gap and passed Yamaha team-mate Rossi to finish third with seven laps remaining.
Marquez and Dovizioso traded places constantly inside the final three laps, with the Spaniard making the crucial move over his Italian rival on the final bend.
"It is not nice to lose on the last corner, but I am really happy. We did incredible work and we continue to improve, "said Dovizioso.
Spanish Ducati rider Jorge Lorenzo missed the race after suffering a wrist injury following a crash in practice on Friday.
1. Marc Marquez (Spa/Honda) 39mins 55.722secs
2. Andrea Dovizioso (Ita/Ducati) +0.115
3. Maverick Vinales (Spa/Yamaha) +0.270
4. Valentino Rossi (Ita/Yamaha) +1.564
5. Johann Zarco (Fra/Yamaha Tech3) +2.747
6. Alex Rins (Spa/Suzuki) +3.023
7. Cal Crutchlow (GB/LCR Honda) +6.520
8. Alvaro Bautista (Spa/Ducati) +6.691
9. Danilo Petrucci (Ita/Ducati Pramac) +9.944
10. Jack Miller (Aus/Ducati) +11.077
1. Marc Marquez (Spa/Honda) 271 points
2. Andrea Dovizioso (Ita/Ducati) 194
3. Valentino Rossi (Ita/Yamaha) 172
4. Maverick Vinales (Spa/Yamaha) 146
5. Jorge Lorenzo (Spa/Ducati) 130
6. Cal Crutchlow (GB/LCR Honda) 128
7. Danilo Petrucci (Ita/Ducati Pramac) 126
8. Johann Zarco (Fra/Yamaha Tech3) 123
9. Andrea Iannone (Ita/Suzuki) 113
10. Alex Rins (Spa/Suzuki) 102
-- Courtesy of BBC Sport