Viviani sprinted clear of Sagan, with Fabio Sabatini (Etixx-QuickStep) in third. British rider Chris Latham (Team Wiggins) finished in eighth spot.
The 26-year-old Italian adds the win to 2015 stage victories in the Giro d'Italia, Tour of Britain (three stages), Eneco Tour and Dubai Tour.
Viviani takes the overall lead in the inaugural edition of the race with two stages remaining, sitting at the same time as stage one winner Andrea Guardini (Astana). Sagan is third overall at four seconds.
"About a kilometre from the finish, I had to make a big effort to get on Sagan's wheel," said Viviani as he recounted the victory. "On the final corner, Palini and another rider moved on the inside, but I did not like the look of it and held back.
"Sagan went, and I knew I had to wait, but not too long because he is so strong. But sprinting is my job, and I managed to get past him, and I am delighted to have taken another win. The conditions today were considerably better than yesterday, and it was a good day for me and the team."
The stage may have been flat, and the weather marginally cooler than the previous day, but the day was still packed with incidents.
Tom Boonen (Etixx-QuickStep) and Theo Bos (MTN-Qhubeka) are out of the race after suffering injuries as a result of a crash after 55km of the relatively short 129km stage from the Yas Marina Formula 1 circuit.
To add to the unexpected incidents, German Paul Voss (Bora Argon 18) was disqualified after he had a verbal disagreement with Federico Zurlo (UnitedHealthcare) during the run-up to an intermediate sprint.
Voss was squeezed into the side of the (wide) road by Zurlo, and gesticulated wildly after having to brake sharply and miss out on contesting the sprint. Voss - who held the intermediate sprint classification lead - paid for his display of anger with disqualification.
Tomorrow the riders face something different: Saturday's stage three features an 11-kilometre long climb to the finish line, and is likely to decide the overall classification ahead of Sunday's flat finale.
>>> Abu Dhabi Tour 2015: What you need to know
Abu Dhabi Tour 2015, stage two: Yas Marina Circuit to Yas Mall, 129km
1. Elia Viviani (Ita) Team Sky in 3-02-07
2. Peter Sagan (Svk) Tinkoff-Saxo
3. Fabio Sabatini (Ita) Etixx-QuickStep
4. Luka Mezgec (Slo) Giant-Alpecin
5. Lukasz Wisniowski (Pol) Etixx-QuickStep
6. Andrea Palini (Ita) SkyDive Dubai
7. Jose Joaquim Rojas (Spa) Movistar
8. Chris Latham (GBr) Team Wiggins
9. Marco Canola (Ita) UnitedHealthcare
10. Michael Schwarzmann (Ger) Bora-Argon 18 all same time
Overall classification after stage two
1. Elia Viviani (Ita) Team Sky
2. Andrea Guardini (Ita) Astana at same time
3. Peter Sagan (Svk) Tinkoff-Saxo at 4 secs
Thank you for reading 5 articles this month* Join now for unlimited access
Enjoy your first month for just £1 / $1 / €1
*Read 5 free articles per month without a subscription
Join now for unlimited access
Try first month for just £1 / $1 / €1