The Manxman held onto his second place after contesting the points race, which was fiercely competitive as riders made last gasp attempts to grab a podium spot.
Cavendish faced his biggest competition from third place Lasse Norman Hansen (Denmark), who managed to take an early lap on the field with around 115 laps remaining, putting he and the Briton on almost level pegging throughout the rest of the race.
Hansen held the silver position for a short time, but Cavendish consistently took points in the intermediate sprints and at one point looked to be gaining on Viviani, who kept his composure throughout the race despite being caught in a crash.
>>> My toughest day: Elia Viviani (video)
That crash saw Sanghoon Park of South Korea carried from the track on a stretcher, after Cavendish appeared to clatter into the side of him after drifting down from the top of the track. Australian Glenn O'Shea was also brought down but was able to continue.
World champion Feranando Gaviria (Colombia) was incredibly active and consistently attacked, even in the opening lap of the race, but couldn't move himself onto the podium after starting the race in seventh place overall.
By the end of the race, Cavendish was simply marking Hansen after realising he wasn't going to be able to catch Viviani, securing himself the silver medal.
The Manxman missed out on medals in the madison at Beijing 2008 and in the road race at London 2012, but added the silver to an already supreme palmarès which includes 30 stage wins of the Tour de France.
2016 Olympic Games, Men's Omnium, final overall standings:
1. Elia Viviani (ITA) 207
2. Mark Cavendish (GBR) 194
3. Lasse Norman Hansen (DEN) 192
4. Fernando Gaviria (COL) 181
5. Thomas Boudat (FRA) 172
6. Roger Kluge (GER) 167
7. Glenn O’Shea (AUS) 144
8. Dylan Kennett (NZL) 143
9. Tim Veldt (NED) 111
10. Artyom Zakharov (KAZ) 111
11. Leung Chun Wing (HKG) 105
12. Gael Suter (SUI) 95
13. Gideoni Monteiro (BRA) 94
14. Kazushige Kuboki (JPN) 81
15. Ignacio Prado (MEX) 73
16. Sanghoon Park (KOR) DNF
17. Bobby Lea (USA) DNF
18. Jasper de Buyst (BEL) DNF
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