Viviani was consistently strong over the two-day, six-event race and beat British road sprint star Mark Cavendish into second, with 2012 gold medallist Lasse Norman Hansen of Denmark third.
The Italian even recovered from a fall a third of the way into the final event, the 40km points race, to dust himself down and hold off determined challenges from a number of riders.
Cavendish rode a controlled points race but Viviani marked him throughout, the Briton unable to make significant inroads into the Italian's lead, which he held since winning the third discipline late on Sunday.
Hansen, whose own hopes suffered a crushing blow on Sunday when he finished last in the elimination race, started clawing his way back into contention by gaining a lap in the points race.
But he didn't have enough juice left to take crucial sprint points as Cavendish eventually settled for keeping hold of second place rather than challenging Viviani for the win.