The Sky rider crossed ahead of Dutch cyclist Moreno Hofland and Germany's Andre Greipel after 4hr 13min 18sec in the saddle, as Michael Matthews took the overall leader's pink jersey from Orica teammate and fellow Australian Simon Gerrans.
Slovenian Luka Mezgec placed fourth ahead of Italian Alessandro Petacchi.
It was the first stage win in a major Tour for 26-year-old Viviani, a two-time world track championship medallist last February.
Matthews, 24, pulled on the pink jersey for the seventh time, after also grabbing it on the second stage last year.
Five riders – Marco Frapporti, Lukasz Owsian, Giacomo Berlato, Eugert Zhupa and Bert-Jan Lindeman – lead a long breakaway building a lead of nine minutes before being caught 11km from the line in the outskirts of Genoa.
The stage was also peppered with falls, notably Australian champion Heinrich Haussler and Italy's Matteo Pelucchi who crashed in the final stretch.
Monday's third stage is a 136km run through the Ligurian countryside between Rapallo and Sestri Levante.