Contador (Tinkoff-Saxo) first took the Giro lead on Stage 5 then lost it momentarialy to Fabio Aru (Astana) after Stage 13. But he never relinquished his hold on the pink jersey after the Stage 14 individual time trial where he finished third behind Team Sky's Vasil Kiryienka.
He then sealed his victory on Stage 20 after riding defensively following an all-out assault by Aru and Astana on the brutal nine kilometre climb up the dirt roads of the Colle delle Finestre.
Aru finished second overall behind Contador with his Astana team-mate Mikel Landa securing third place.
With the victory Contador is looking to become the first rider to achieve a rare Giro/Tour de France double since the late Marco Pantani in 1998.
"During the three hard weeks of the Giro, everything imaginable has happened," Contador said. "I came here thinking about victory having prepared very carefully, but then I had my fall and a shoulder injury.
"There was the mythical climb of the Mortirolo, but then yesterday on the Colle delle Finestre I had bad legs. It has been a beautiful Giro, and a very special experience for me.
"I don't know how long it will take to recover. I'm tired, and I know it will take time. It has been an emotional Giro for me. I've said it will be my last, but you never know."
As is traditional in Grand Tours the final day of the 98th Giro d'Italia is more a procession than a battle but there was still enough left for the sprinters to have the final say in both the finale and in settling the points classification.
However, in a rare event for a final Gtrand Tour stage, the spoils went to the breakaway after the sprint trains could not get themselves organised to position their finishers.
Together Iljo Keisse (Etixx-QuickStep) and Australia's Luke Durbridge (Orica-GreenEDGE) engineered an escape which stuck to the finish.
And after a messy, flat riddled final three laps of the 5.35km finishing street curcuit in Milan it was the experienced Keisse who used his sprinting advantage took the win on the 178km stage from Torino to Milano ahead of the 24-year-old Durbridge (Orica-GreenEDGE). Roger Kluge (IAM) won the bunch sprint for third.
"We had a sort of plan for me and Saba (Fabio Sabatini) to try and do something on the final bend, because I'm a track rider so I corner pretty well. But then I saw that there was some hesitation at the start of the circuit, so I attacked. I had a pretty good partner in crime in Luke Durbridge," Keisse said.
"I did my last pull at 2.5km. I heard we had 30 seconds so I knew we'd make it. I put pressure on him by saying I wasn't going to work, and I've seen how Cavendish does it so I used that experience today.
"It's been a very different Giro this year for the team. We haven't won a stage, after being very successful in the previous couple of years, so this win is very important. It's my best ever victory, and I'm so, so happy."
The sprinters points battle ended with Giaccomo Nizzolo (Trek Factory Racing) taking the classification ahead of Sasha Modolo (Lampre-Merida) and Elia Viviani (Sky).
Stage 21: 128km, Torino-Milan
1 Iljo Keisse (BEL) Etixx-QuickStep 4hr 18min 37sec
2 Luke Durbridge (AUS) Orica-GreenEDGE
3 Roger Kluge (GER) IAM 00:00:09
4 Alexander Porsev (RUS) Katusha
5 Giacomo Nizzolo (ITA) Trek Factory Racing
6 Luka Mezgec (SLO) Giant-Alpecin
7 Elia Viviani (ITA) Sky
8 Moreno Hofland (NED) LottoNL-Jumbo
9 Davide Appollonio (ITA) Androni Giocattoli
10 Elia Favilli (ITA) Lampre-Merida
1 Alberto Contador (ESP) Tinkoff-Saxo 88hr 22min 25sec
2 Fabio Aru (ITA) Astana 0:01:53
3 Mikel Landa (ESP) Astana 0:03:05
4 Andrey Amador (CRC) Movistar 0:08:10
5 Ryder Hesjedal (CAN) Cannondale-Garmin 0:09:52
6 Leopold Konig (CZE) Sky 0:10:53
7 Steven Kruijswijk (NED) LottoNL-Jumbo 0:11:21
8 Damiano Caruso (ITA) BMC 0:12:08
9 Alexandre Geniez (FRA) FDJ 0:15:41
10 Yuri Trofimov (RUS) Katusha 0:16:41