The Spaniard was helped into a good position by his Saxo-Tinkoff Team, who closed down a five-man break near the foot of the final mountain.
And, after a series of deep attacks, Contador shed the opposition to finish two seconds ahead of overall leader Daniel Diaz.
“The entire team worked hard to prepare Alberto for the final," Team Saxo-Tinkoff sports director Philippe Mauduit said.
"The boys made everyone suffer out there with a high pace before and on the final climb where Alberto was simply relentless.
"He really insisted on breaking clear to take this win and finally, no one was able to match his determination."
Contador moves up to fourth overall.
Stage 6 results:
1. Alberto Contador
2. Daniel Diaz + 0.02s
3. Alex Diniz + 0.02
4. Arnold Alcolea + 0.14
5. Mauro Santambrogio + 0.14
1. Daniel Diaz
2. Tejay van Garderen + 0.33
3. Alex Diniz + 0.39
4. Alberto Contador + 1.02
5. Jurgen van den Broeck + 1.47