Dovizioso and Marquez formed part of a 10-bike queue that headed the field for much of the race, with poleman Johann Zarco converting pole position into an early lead aboard the Tech 3 Yamaha.
It wasn't until lap 18 of 22 that Dovizioso and Marquez finally made their moves, both passing Zarco at Turn 1 and quickly distancing the Frenchman to engage in their own private duel for victory.
In scenes reminiscent of their battles last year in Austria and Japan, the two 2017 title protagonists ran nose to tail for the final laps, with Marquez attempting a pass at the final corner on the last lap. But Dovizioso managed to edge back ahead exiting the turn, getting superior traction and outdragging Marquez to the finish line by the tiny margin of 0.027s for his ninth career MotoGP victory.
Seven tenths behind the lead duo was Valentino Rossi, who passed Zarco on the same lap as Dovizioso and Marquez but couldn't keep up the pace in the closing laps.
Cal Crutchlow was fourth on the LCR Honda, a further two seconds behind, ahead of Danilo Petrucci's Pramac Ducati. Both had been part of the leading group bottled up behind Zarco, but the extra lap they took to clear the satellite Yamaha allowed the leading three to escape.
Zarco ended up slumping to eighth at the finish, losing out to the second works Yamaha of Maverick Vinales and the second factory Honda of Dani Pedrosa in the latter stages.
Last year's Qatar winner Vinales circulated as low as 15th in the early laps but managed to recover to salvage sixth at the end of a difficult weekend.
Andrea Iannone was top Suzuki rider in ninth, although teammate Alex Rins was running sixth when he crashed at Turn 2 on lap 12.
Falling on the same lap was Ducati's Jorge Lorenzo, who was running just outside the top 10 on the second factory GP18 when he appeared to suffer a brake problem.
Jack Miller completed the top 10 on the second Pramac Ducati, followed by Avintia Ducati's Tito Rabat and top rookie Franco Morbidelli (Marc VDS Honda).
Alvaro Bautista (Nieto Ducati), debutant Hafizh Syharin (Tech 3 Yamaha) and Karel Abraham (Nieto Ducati) rounded out the scorers.
Bradley Smith led KTM's efforts in 18th place, with teammate Pol Espargaro retiring in the pits with mechanical failure.
Aprilia duo Aleix Espargaro and Scott Redding trailed home 19th and 20th, although Espargaro ran out of fuel and dropped some 20 seconds on the final lap having run just outside the top 10 for much of the race.