Sam Bennett (BORA-hansgrohe), was in the lead with a kilometre to go but Viviani (Quick-Step Floors) showcased his impressive power before the final corner to cross the finish line first.
Sacha Modolo (Cannondale-Drapac) finished second as Bennett faded into third on the 229km stage from Be'er Sheva to Eilat, the longest of this year's race.
Jakub Mareczko (Wilier Triestina-Selle Italia) and Danny van Poppel (LottoNL-Jumbo) rounded out the top five.
“Today, the race was maybe what we imagined in the middle of the desert, with around 2000 metres of ups and downs," Viviani said.
"All GC riders and sprinters teams rode at the front. Some riders lost contact as it was not an easy stage. The speed of the sprint was a bit low because of the corner with 350 to go. The wind also went up in the last few kilometres. Luckily it wasn’t as hot as we feared.
"There was some contact between Sam Bennett and myself in the sprint. I was already on his side when he made a clear move to the barriers, he was pushing me towards the roadside but I made him understand that I was already there.
"With Quick-Step, I have the best team for the sprints and whatever I can win, I bring it home, regardless of who my rivals are. It doesn’t matter what the other top sprinters are doing at the moment, I’ve already faced them at the beginning of the season.
"I have chosen to do the Giro this year. I have already taken part in all three Grand Tours and I consider the Giro as the most difficult to finish. It’s my goal to complete it with the Maglia Ciclamino this year.”
BMC's Dennis stayed out of danger on the stage and he will have the advantage when the race resumes after a rest day in Catania, Sicily on Tuesday.
He remains one second clear of Sunweb's Tom Dumoulin and 13 clear of José Gonçalves (Katusha-Alpecin) on the general classification.
“This is the first time I have retained the leader’s jersey of a Grand Tour," Dennis said. It makes it one goal achieved for this Giro and to take the Maglia Rosa to Italy is something special.
"It’s been stressful today, quite nerve-wracking, but I’m glad I got through unscathed as with 5km to go, I thought I wouldn’t hold onto the jersey.
"I’ve been nicely surprised with Israel: when we race outside of Europe, Australia or the US, it’s pretty quiet on the roads. Here it’s been the complete opposite.
"Fans have supported us as if they were a real big cycling country. This amount of enthusiastic people is scary sometimes but it’s definitely better than an absolute silence.”
Israel Cycling Academy's Guillaume Boivin was cheered on by the home crowd as the Canadian, along with Marco Frapporti (Androni Giocattoli-Sidermec) and Enrico Barbin (Bardiani-CSF), led the race from the start.
The trio was swept up by the peloton in the closing stages and finished well behind the top 10 in the last stage to be held in Israel.
Esteban Chaves and Simon Yates of the Australia-based Mitchelton-Scott team finished 15th and 16th respectively.