Tour de France champion Bradley Wiggins dropped out of contention, finishing more than 3 1/2 minutes behind the main pack as he struggled with a cold and chest infection. There were questions over whether he would withdraw overnight.
Cavendish clocked just over 3 hours along the 134-kilometre (83-mile) route from Longarone to Treviso, which started with a few hills and ended with a long, flat finish around a circuit.
It was Cavendish's third win in this year's race. The British rider with the Omega Pharma-Quick Step team also won the first and sixth legs.
"I couldn't wait to get my 100th win and I'm very pleased to have done it here at the Giro," Cavendish said. "But more than the fact I've won here, I'm proud of how we did it. We came here with the intentions of trying to win every sprint. We haven't just won every sprint, we've won it quite convincingly. We controlled the peloton from start to finish today, in quite horrid conditions."
Nacer Bouhanni of France and Luke Mezgec of Slovenia crossed second and third, respectively, with the same time.
Dominique Rollin of Boucherville, Que., was the top Canadian in the stage, finishing 19th. Defending champion Ryder Hesjedal of Victoria continued to struggle, finishing 183rd.
In the overall standings, Nibali, an Italian with Astana, remained 41 seconds ahead of 2011 Tour winner Cadel Evans of Australia. Wiggins' Sky teammate Rigoberto Uran of Colombia is third overall, 2:04 behind.
Robert Gesink of the Netherlands is fourth, 2:12 back. Michele Scarponi, the Italian who won the 2011 Giro when Alberto Contador was stripped of the title for doping, is fifth, 2:13 behind.
Wiggins dropped from fourth to 13th place, 5:22 behind Nibali.
"Since he broke his collarbone (in 2011), I can't remember a period where he was particularly ill," Sky general manager Dave Brailsford said on the team's website. "We had a lot of things that went our way and we didn't have any setbacks, but in the fullness of time, that is going to come along and you have to take it in your stride."
Hesjedal was 38th overall while Rollin was 101st.
Nibali wasn't interested in assessing Wiggins' troubles.
"Uran is riding great," the leader said. "The standings are still very close and Evans is right there. Scarponi is also pedalling well."
It was the 13th Giro stage win of Cavendish's career and his 39th in cycling's three Grand Tours — the Giro, Tour and Spanish Vuelta.
Stage 13 Friday is the race's longest, a mostly flat 254-kilometre (158-mile) leg from Busseto to Cherasco, with a few hills shortly before the finish.
The race hits the mountains again over the weekend, with Saturday's stage climbing Sestriere and Bardonecchia and Sunday taking riders into France and up the Col du Galibier, which is often included in the Tour de France.
The race ends May 26 in Brescia.