The Italian, who won the 2013 Giro, was battered and bruised after a terrible performance in last Sunday's uphill time trial and Tuesday's mountain stage to Andalo, but when all seemed lost he hit back in style.
The Astana rider won solo in Risoul on Friday when overall leader Steven Kruiswijk (LottoNL-Jumbo) crashed, and he put the hammer down on Saturday by dropping his closest rivals Alejandro Valverde (Movistar) and Esteban Chaves (Orica-GreenEdge), who was wearing the pink jersey.
"Steven Kruijswijk had a good advantage after the Dolomites but I knew the highest mountains were yet to come. Riding above 2000 metres isn’t easy for anyone but I found myself in good shape," Nibali said.
"Kruijswijk crashed but towards the summit of the Colle d’Agnello, I noticed he was breathing heavily so I put pressure on him climbing and then descending.
"Had I not done so, probably nothing would have happened and Chaves would have had an easy ride as well. Everyone was watching me and I wasn’t used to race guys like Dumoulin, Chaves and Kruijswijk."
Nibali is one of only six men to win all three grand tours; the 2013 Giro, 2010 Vuelta and 2014 Tour de France crowns.
"I don’t often look at my palmarès but when I do, I realize it’s rich of great successes," he said.
His team was reported to have considered pulling him from the race earlier this week after his mediocre form saw him slip out of contention.
“I had a stomach bug during the Giro but it’s better not to tell everything sometimes," he said. "The last rest day allowed me to get better.
"I never said that I wanted to go home. I always remained in the high part of the classification."
The first to win the Giro as the Italian champion since Felice Gimondi in 1969, Nibali eventually beat Colombian Chaves by 52 seconds and Valverde by 1 min 17 secs.
It is Valverde's seventh podium in a grand tour although he has only won one, the Vuelta 2009.