Marquez and Dovizioso are now tied on 199 points with Spaniard Maverick Vinales, who finished fourth for Yamaha, third on 183.
The top two have both won four races but Marquez has more second places.
Vinales had started on pole position and was the sole works Yamaha rider in the race after Italian Valentino Rossi, who is fourth in the championship on 157 points, broke his leg in training last week.
However it was fellow-Spaniard and triple MotoGP champion Jorge Lorenzo who made a lightning start to take the lead on the opening lap for Ducati.
Lorenzo pulled away but crashed on the seventh of 28 laps, flipping off the bike at turn six and handing the lead to Petrucci.
The Italian, who has yet to win a race in the top category, then led the next 20 on his Pramac Ducati with Marquez closing in and biding his time before making the move at the start of the last lap.
“In rainy conditions you never know but I was trying to control all the race, trying to control myself because I was able to be a little bit faster but I said ‘you must be patient’,” said Marquez.
“For a moment I thought of staying in second position. Then on the last lap I said ‘I try’. This championship is really tight and five points can be a lot in the end.”
“After Silverstone this victory is really important for myself and the team,” added the 24-year-old, who retired with a blown engine in the previous round in Britain. His last lap was also the fastest of the race.
Dovizioso, who would have been the oldest rider to win three races in a row since Australian Mick Doohan in 1998 had he continued his run of success from Austria and Silverstone, said he was happy with a first podium at Misano.
“I was there, but I wasn’t feeling so good on the bike so the risk was too high. Everybody almost crashed today,” he said.
“It was a very difficult weekend but we are there and did another podium in a strange and difficult moment.”
(Reporting by Alan Baldwin in London, editing by Toby Davis)