Ducati's Dovizioso was well ahead of second-placed Suzuki rider Alex Rins with another Spaniard Pol Espargaro third in a race halted for around 30 minutes due to the rain.
Marquez pulled out after going over his handlebars at an early corner following a spectacular high-speed loss of control.
Yamaha's Valentino Rossi was another high-profile faller, his late exit from second position allowing Espargaro and KTM to clinch a place on the podium for the first time in the premier class.
Rossi still finished the championship in third place, behind Dovizioso and Marquez.
Dovizioso's victory was his fourth of the season and a first for Ducati in Valencia in 10 years.
"It was a crazy race, at the beginning I didn't have a lot of feeling and Rins started so fast, I couldn't follow him," Dovizioso told reporters.
"Step by step, I became a bit faster and it was very dangerous. I am proud not to crash because there was too much water.
"After the restart we made some changes on the bike and we put on new tyres and I felt so good, the bike worked well and I was able to push as much as I wanted and it was too much for the competitors.
"It's a nice feeling to finish the championship like this."
On his first podium finish, Espargaro said: "Even fourth would have been an unbelievable position. I am so proud, to be here on the podium, standing with the best bikes in the world. I'm super happy."
Michele Pirro, also of Ducati, came fourth while Honda's Dani Pedrosa finished fifth in his last MotoGP race before retirement.
- 'Crazy race' -
Rins had led for the majority of the race, including after a red flag reset the standings to lap 13, as wet conditions became too dangerous to continue.
"I am very happy, it was a crazy race," Rins said. "We feel we are ready for next season."
There were numerous crashes in the Moto3 and Moto2 races earlier on Sunday while Marquez started the race fifth, after the Spaniard injured his shoulder in a fall during qualifying on Saturday.
Maverick Vinales, on pole, had said he was only targetting a top-seven place given the challenging conditions at the Circuit Ricardo Tormo and he quickly surrendered his advantage to Rins, who led by almost two seconds after only the opening lap.
Rossi started 15th on the grid but shot up to eighth as several riders fell victim to the weather.
Aleix Espargaro, Danilo Petrucci and Jack Miller all crashed before Marquez also twisted out through Turn 9.
Rins gave up his lead, running wide around a turn as both Dovizioso and Rossi passed through, only for the rain to become too severe, pushing the race back to lap 13.
When the action resumed, Rins was again overtaken by the chasing pair, but Rossi failed to keep pace with Dovizioso and crashed out on Turn 12, with just five laps remaining.
Rins crossed the line 2.750secs behind Dovizioso, while Espargaro and Pirro recovered from earlier falls to take third and fourth respectively.
It means Marquez, who confirmed his fifth world title in Japan last month with three races to spare, finished 76 points ahead of Dovizioso in the overall standings.
Rossi snatched third, two points in front of his Yamaha team-mate Vinales, with Rins a further 44 points back in fifth.