Up front, Denifl continued to press on, with Contador rapidly shutting the gap down behind him with a superb ride.
The Austrian had enough, however, pushing hard as he got over the top of the steepest part of the climb and surged to victory.
Contador was second, 25 seconds later, gaining time on the four riders ahead of him in the GC as a result, while Miguel Angel Lopez (Astana) took third, and the final bonus seconds, ahead of Nibali.
Froome was led in by Nieve some 42 seconds, limiting his losses in the process but also losing most of the minute he had gained the previous day.
He now leads overall by 1’16” from Nibali, with Wilco Kelderman (Team Sunweb) third at 2’13”.
Vuelta a Espana 2017: stage 17 – result
1) Stefan Denifl (AUT) – Aqua Blue Sport – 4.48.52hrs
2) Alberto Contador (ESP) – Trek-Segafredo +28”
3) Miguel Angel Lopez (ESP) – Astana +1.04
4) Vincenzo Nibali (ITA) – Bahrain-Merida – ST
5) Ilnur Zakarin (RUS) – Katusha-Alpecin
6) Rafal Majka (POL) – Bora-hansgrohe
7) Michael Woods (CAN) – Cannondale-Drapac +1.13
8) Daniel Moreno (ESP) – Movistar +1.17
9) Wilco Kelderman (NED) – Team Sunweb +1.19
10) David de la Cruz (ESP) – QuickStep Floors +1.42
General classification
1) Chris Froome (GBR) – Team Sky – 67.44.03hrs
2) Vincenzo Nibali (ITA) – Bahrain-Merida +1.16
3) Wilco Kelderman (NED) – Team Sunweb +2.13
4) Ilnur Zakarin (RUS) – Katusha-Alpecin +2.25
5) Alberto Contador (ESP) – Trek-Segafredo +3.34
6) Miguel Angel Lopez (COL) – Astana +4.39
7) Michael Woods (CAN) – Cannondale-Drapac +6.33
8) Wout Poels (NED) – Team Sky +6.40
9) Fabio Aru (ITA) – Astana +6.45
10) David de la Cruz (ESP) – QuickStep Floors +10.10