Astana rider Nibali needed only to avoid disaster in the final stage to claim the title, and he finished safely in the leading bunch to claim a second Grand Tour victory of his career to go with his 2010 Vuelta a Espana crown.
Sky's Rigoberto Uran finished second in the general classification with Cadel Evans (BMC) in third.
Cavendish was perfectly placed going into the final stretch of the 21st and final stage, and blasted down the final 200m to edge Sacha Modolo for the win, with Elia Viviani coming third.
"I came here with a team that wanted to win the Giro, that was united with me from beginning to end and which really supported me all the way through," Nibali said after hoisting his trophy.
"And I knew from stage eight that I could win the Giro this year. And I have.
"My only serious difficulty came in the stage seven finish at Pescara, when I crashed twice on the descent, and I didn't know if I was going to recover from that."
Uran's runners-up spot is the best position for a Colombian rider in the Giro's history.
"I couldn't be happier, I came here with one job, which was to work for (leader and team mate) Bradley Wiggins, but when he had to abandon the team regrouped around me and I've got on the podium," Uran told reporters.
"If I can, I'm going to come back here and win the Giro next year."
Evans, at 36 years three months, is the oldest rider to make it onto a Giro podium since 1928.
"I came to this Giro with few reference points from earlier in the season and little by little I've come through," Evans told reporters.
"But I'll be back at the Tour, which is my team's biggest target of the season."
Cavendish was thrilled after a win that makes him the fifth rider to claim the points jersey on all three Grand Tours.
"I lost it by so little last time and there was no way I was going home without it this year," a jubilant Cavendish said.
After some horrendous weather over the past three weeks, Cavendish had his day in the sun on the final day.
The Manx Missile lost the points classification red jersey to race winner Vincenzo Nibali on Saturday, and it was clear from the off that Sunday's 197km stage between Riese Pio X and Brescia was to be all about the sprinters.
Stage 21 included two intermediate sprints and always looked destined for a sprint finish, making it seem a mere formality that Cavendish would make up the 11 point gap between himself and Nibali to wrestle back the red jersey and reach his goal of collecting points classification wins from all three Grand Tours.
The route was pan flat and from the start and Omega Pharma Quick Step set out their stall early on, going to the head of the peloton and keeping things under control.
Steve Cummings (BMC) launched the first attack of the day after 82km, but was quickly reeled in by the Omega Pharma train.
Cavendish's first opportunity to garner some points arrived at just over 125km with the intermediate sprint at Sirmione and he didn't disappoint. His team led him to within a couple of hundred metres of the line and nobody had the power to overtake him.
Following this sprint, attacks came from Maurits Lammertink and Rob Ruijgh of Vacansoleil, but both were short lived as Nibali sent his Astana team mates up front to close things down.
From there the riders came into the first of seven 4.2km laps of Brescia. As the race entered the town, Stefano Garzelli (Vini Fantini) was allowed to ride ahead of the bunch and take the plaudits of the crowd in what is his last Giro d'Italia.
The attacks began after the race crossed the line for the first time. Giairo Ermeti of Androni Giocattoli jumped from the bunch and immediately Cavendish was on his wheel. The Manx man crossed the line first at the end of that lap, but confusion reigned as it turned out that this was not the intermediate sprint point.
One lap later and Omega Pharma had regained control and it was to be Cavendish's day as he jumped out from behind his lead-out train to secure enough points to claim the red jersey as his own.
Behind Cavendish the top three were unconcerned and rode along in celebratory mood. Following his total dominance atop the Tre Cime di Lavaredo, Nibali claimed his first Maglia Rosa with Uran (Sky) taking second, and Evans (BMC) completing the podium despite his mechanical problems on Stage 20.
The final laps played almost entirely into Cavendish's hands. His Omega Pharma Quick Step team kept the pace high through the twisting and turning finishing circuit right up until the final lap. At this point, Cannondale, working for Viviani, muscled their way to the front.
As the bunch rounded the final corner Cavendish was sitting behind the Cannondale train, and though he was forced to go for a very long drag race he never looked in danger of failing to claim the stage win .
This has been a difficult edition of the Giro d'Italia and each of the 168 riders who completed the course will be looking forward to some hard-earned time off.
In the other competitions, Stefano Pirazzi (Bardiani Valvoli CSF Inox) claimed the blue mountains classification jersey, while a storming ride on Saturday was enough for Carlos Betancur (AG2R) to hold on to his white young rider jersey from Rafal Majka (Saxo Tinkoff).
The team classification was taken by Sky, small consolation for losing their team leader, but it has been a successful event for the British team with Uran finishing in second overall.
- Sports & Recreation
- Rigoberto Uran
- Cadel Evans