Frenchman Fabio Quartararo came third, which enabled him to climb two spots in the overall classification to the seventh place.
Marquez headed into the last lap leading the race, but as he tried to secure the win, his opponent took him by surprise in the last turn of the final circuit, Efe news reported.
The Spaniard tried to extend the domination he has displayed over the weekend from the beginning of the race.
But he once again found himself face-to-face with Dovizioso after both staged a one-on-one competition through several turns.
During the first lap, Quartararo managed to take an advantage of a few metres and Dovizioso came second, while the Repsol Honda rider, who tried to avoid mistakes, was nipping at the heels of Ducati Desmosedici's Jack Miller of Australia.
In the early stages, the race lost two riders as Briton Cal Crutchlow hit the ground and Spaniard Pol Espargaro quit due to technical issues.
During the fourth lap, Marquez overtook Miller to position himself behind Dovizioso, who was closing the gap with Quartararo.
Dovizioso took the lead in the fifth lap with a new lap record.
It was in the next lap that Marquez decided to surpass Quartararo to chase Dovizioso.
Then Marquez went after Dovizioso's position in the eighth lap, overtaking him after a back and forth.
Marquez seemed to be on his way for a maiden win at the Red Bull Ring, but with 19 laps to go, the race was far from finished, especially with Dovizioso not throwing in the towel.
The Spaniard fended off several attempts by Dovizioso, who intensified his efforts in the final three laps.
Dovizioso then managed to turn the table in a nail-biting final lap.
( With inputs from IANS )