Spain's Contador started the day with a 2:35 lead and now has an advantage of four minutes two seconds over compatriot Mikel Landa (Astana), who won the 16th stage 38 seconds ahead of Dutchman Steven Kruijswijk.
Contador also ended the punishing 177-km mountain stage 38 seconds behind.
Astana leader Fabio Aru of Italy finished 2:51 off the pace and dropped to third overall, 4:52 behind Contador, who is looking to achieve a rare Giro/Tour de France double this season.
“It was a very hard day, an incredible stage. Cycling isn't mathematics: I had a puncture on the descent, Ivan Basso gave me a wheel, but ahead they were going at full speed, and it was impossible to close the gap immediately,” said Contador.
“It was hard for me, but I'm very happy with the time gaps now. I would have liked to have helped Steven Kruijswijk, but it was not to be. To Mikel Landa, I can only say: chapeau. These are the stages that people remember.”
While Contador tried to deal with the puncture, the Astana riders upped the pace and opened a gap of almost one minute, but the move backfired.
At the foot of the penultimate climb, an intimidating ascent to the Passo del Mortirolo, Contador was lagging 45 seconds behind but went solo and soon caught a small group featuring Landa and Aru.
He attacked them and only Landa could follow as Aru cracked, thus limiting the damage until the finish line.
The last rider to achieve a Giro/Tour double was the late Marco Pantani of Italy in 1998.
Original source: Contador extends Giro lead