Deceuninck-Quick-Step were able to come to the front of the peloton with perfect timing with 1.3km to go, with Danish champion Michael Mørkøv leading out Viviani perfectly until 200m to go.
>> Struggling to get to the shops? Try 6 issues of Cycling Weekly magazine for just £6 delivered to your door <<
Sagan, sitting on Viviani’s wheel, took the longer way to the line as he jumped to the right of Mørkøv, with Viviani going to the left and hugging the barriers as the road curved leftwards to the line.
Once the Italian champion had unleashed his full effort there was little Sagan could do to catch him, with Matthews showing the best turn of speed as he came late to steal second place from the three-time world champion on the line.
Sagan however holds on to the overall race lead thanks to his third place finish.
The big news coming from the stage is the abandonment of defending Tour de France champion Geraint Thomas (Team Ineos), who crashed with around 30km to go, suffering abrasions and a visible cut to the head.
How it happened
The peloton faced a tricky 163.6km fourth stage at the Tour de Suisse, with tough climbing along the route. The two category three climbs of the route, interspersed by some unclassified climbing, may not be enough to stop the sprinters reaching the finish, but could play in favour of the breakaway.
Four men decided to get in the day’s main break, with Robin Carpenter (Rally UHC), Simon Geschke (CCC Team), Gian Friesecke (Switzerland) and Taco van der Hoorn (Jumbo-Visma) getting up the road.
With a fairly flat opening 80km or so to the stage, the break were gradually able to build their lead to a maximum of around 3-30 heading into the final 100km.
As the race began to head uphill, the break continued to work well together but couldn’t stop the gap dropping to around 2-30 with 50km to go.
The advantage continued to gradually drop for the break, but the next drama came from the peloton with 30km remaining.
Up front, the break were now hitting the final climb and with 19km to go, with Geshcke and Friesecke deciding to hit out with gap now down to just a minute.
Geshcke was unable to match the Swiss rider’s pace up the climb, with Friesecke then out front alone with a 50-second advantage.
Bora-Hansgrohe were now hammering it on the front to try and set up race leader Peter Sagan for the sprint finish.
The pace set by the German team meant Friesecke was never going to last long, and after taking the final intermediate sprint, he was caught with 11km to go.
From then on the pace was high, though no team could really control affairs.
That saw numerous attacks from riders attempting to go long, with Stefan Küng (Groupama-FDJ), Matej Mohorič (Bahrain-Merida) and Mathias Frank (Ag2r La Mondiale) all trying in vain to break clear individually.
Trek-Segafredo and Bora came back to the front in final 3km, with Elia Viviani’s Quick-Step team nowhere to be seen.
A late move by them though to the front with 1.3km to go saw Sagan jump on Viviani’s wheel, as Yves Lampaert, Kasper Asgreen, and Michael Mørkøv all took their turns on the front to lead out the Italian.
Last man Mørkøv dropped off his sprinter with 200m to go, with Viviani choosing the fastest route to the left to give him the edge over Sagan.
The race leader seemed to fade slightly towards the line as Michael Matthews was able to make a late dash for third place.
The Tour de Suisse heads for hillier terrain on stage five, with the sprinters unlikely to make it over the category two climb at just over 30km from the line in touch with the peloton. The route takes on 177km from Münchenstein to Einsiedeln.
Tour de Suisse 2019, stage four: Murten to Arlesheim (163.9km)
1. Elia Viviani (Ita) Deceuninck-Quick-Step, in 3-46-02
2. Michael Matthews (Aus) Team Sunweb
3. Peter Sagan (Svk) Bora-Hansgrohe
4. Matteo Trentin (Ita) Mitchelton-Scott
5. Jasper Stuyven (Bel) Trek-Segafredo
6. Sep Vanmarcke (Bel) EF Education First
7. Reinardt Janse Van Rensburg (RSA) Dimension Data
8. Iván García Cortina (Esp) Bahrain-Merida
9. Stan Dewulf (Bel) Lotto-Soudal
10. Fabian Lienhard (Sui) Switzerland, all at same time
General classification after stage four
1. Peter Sagan (Svk) Bora-Hansgrohe, in 11-37-28
2. Michael Matthews (Aus) Team Sunweb, at 10s
3. Kasper Asgreen (Den) Deceuninck-Quick-Step, at 15s
4. Rohan Dennis (Aus) Bahrain-Merida, at 16s
5. Lawson Craddock (USA) EF Education First, at 21s
6. Stefan Küng (Sui) Groupama-FDJ, at 25s
7. Matteo Trentin (Ita) Mitchelton-Scott, at 32s
8. Patrick Konrad (Aut) Bora-Hansgrohe, at 33s
9. Jonathan Castroviejo (Esp) Team Ineos, at 34s
10. Luis León Sánchez (Esp) Astana Pro Team, at same time