The world champion used his sprinting power on the uphill finish to the 183km stage from Saint-Lo to Cherbourg to pull clear of Frenchman Julian Alaphilippe with Spain's Alejandro Valverde in third.
Sagan and a select group overhauled Belgian Jasper Stuyven, who had spent almost the entire stage up front, but was caught in the final kilometer.
Cavendish, who won the first stage in Normandy, was distanced on the climb and ceded both yellow and the green points jersey to Sagan.
Race favorite Chris Froome finished 10th, with Nairo Quintana close behind, but two-time champion Alberto Contador lost more time after crashing for the second day in a row.
"I lost more time than I had hoped to lose. I suffered another crash, I hit the handlebars and I was hurt on the other side from yesterday," the Spaniard told the official Tour website.
"The Tour has really started on the wrong footing. I'm not happy at all. It's cycling. I must see if I can make up some time in the Pyrenees and the Alps, see what I can do."
There was misfortune for another leading contender, BMC Racing's Richie Porte of Australia, who punctured with five km to go.
With the pace highest in the peloton as it chased down Stuyven, Porte lost a minute more than Contador.
The flamboyant Sagan was claiming his fifth stage win on the Tour, but his first since 2013. He has won the green points competition for the past four years and is favorite to do so again.
But like Cavendish the day before, this is his first time in yellow.
"It's a very nice jersey. This is something special for sure."
Consolation for Stuyven was taking the polkadot king of the mountains jersey off breakaway companion Paul Voss.
Alaphilippe, who cut a frustrated figure at the end as Sagan powered past, is now second overall at eight seconds with Valverde in third, another two seconds further adrift.
Defending champion Froome, given perfect protection by Team Sky, is fifth at 14 seconds, two places ahead of principle rival Quintana, who is on the same time.
Monday's third stage takes the riders 223.5km from Granville to Angers, with sprint specialists like Cavendish, Marcel Kittel and fellow German Andre Greipel likely to contest the finish.