The 25-year-old Honda rider started from the pole position but lost his lead to Yamaha’s Valentino Rossi. Marquez dropped to third behind Dovizioso.
The Italian rider soon overtook Rossi who also dropped behind Marquez.
As the race approached the final few laps, the top two championship contenders fought tooth and nail for the lead. Marquez eventually prevailed, winning by the slimmest of margins and take a huge lead in the championship standings.
Marquez now has 271 points, 77 ahead of Dovizioso with a maximum of 100 available in the final four races of season.
“I tried to give everything, I forget the championship, I forget all these things,” Marquez said.
“The last five laps were very very nice for the Thai fans.”
Yamaha’s Maverick Vinales finished third ahead of Rossi and Johann Zarco.
Thailand’s inaugural MotoGP was held in the town of Buriram, about a five-hour drive from the capital Bangkok.