The Italian crossed the line at the end of a gruelling 177km ride in a time of 4:08:08, the race having followed the first rest day.
Bora-Hansgrohe’s Peter Sagan slotted into second, while third place went to Trek–Segafredo’s Giacomo Nizzolo.
About 30km into the stage, Katusha-Alpecin’s Tiago Machado and Burgos BH’s Jesus Ezquerra formed the first break of the day.
They maintained their lead as they reached and passed the intermediate sprint. With about 40km remaining they had a gap of 1:45 to the peloton.
At this point there was a crash in the peloton with Lotto-Soudal’s Jelle Wallays and UAE Team Emirates’ Simone Petilli going down.
The latter eventually had to be taken away on a stretcher and lifted into an ambulance after being treated by medics.
The day was widely expected to be one for the sprinters and also featured the 4.9km Alto de Fermoselle climb 30km from the finish, which was the ideal spot for attacks to occur.
Machado and Ezquerra were first to start the climb, which featured a gradient of 5.3 per cent.
Bora-Hansgrohe drove the pace in the peloton, which was a minute behind the leaders, as they prepared Sagan for the final sprint.
With about 30km to go, Ezquerra was dropped by Machado. As the pace rose steadily, Burgos-BH’s Diego Rubio executed a solo attack with 20km to the finish but was eventually swept up by the charging peloton.
The speed increased further with 5km remaining as the sprinters readied themselves for the finish.
Quick-Step Floors took control with 2.5km to the line as they focused on protecting Viviani, who had Sagan on his wheel.
Led out by teammates Michael Mørkøv and Fabio Sabatini, Viviani outpaced world champion Sagan to claim the stage 10 victory.
“It was the most perfect lead out we ever did this year,” said Viviani.
“It’s my 17th win this year, and that win is for all these guys doing the lead out. You saw the lead out they did for me today. It was amazing.”
Mitchelton-Scott’s Simon Yates, who took over the red jersey on Sunday, retained his overall lead.