Primoz Roglic will retain his Vuelta a Espana title in Madrid on Sunday despite Richard Carapaz threatening to inflict more penultimate-stage heartbreak on the Slovenian.

David Gaudu stormed up La Covatilla to claim a magnificent second stage victory of this year's Vuelta, but it was further down the mountain where the drama was unfolding.

Roglic started a brutal, decisive stage 17 on Saturday with a 45-second lead over Carapaz, but the Jumbo-Visma rider was in danger of losing the red jersey on a gruelling final climb to a mountain-top finish.

Hugh Carthy, third in the General Classification standings, made a move with 4.5km to go, yet Roglic and Carapaz reacted and were able to follow the Brit again when he burst away for a second time.

Roglic and Carthy could not catch Ecuadorian climber Carapaz when he decided the time had come to make one massive final push to try and win the race 3km from the end of the gruelling 178.2km stage from Sequeros.

A shattered Roglic looked to be in trouble as he faded and was left isolated as INEOS Grenadiers rider Carapaz darted up the mountain, with the leader struggling on the steeper sections.

Carthy also moved away from Roglic, but the reigning champion dug deep to cross the line 21 seconds after Carapaz, who will have to settle for second place.

Roglic endured the agony of sensationally losing his Tour de France lead to Tadej Pogacar on the decisive stage in September, but he was not to be denied on this occasion despite the best efforts of Carapaz in an enthralling battle.

A second Grand Tour title will be Rogic's at the end of a 124.4km flat processional ride from Hipodromo de la Zarzuela to Madrid on Sunday.

STAGE RESULT

1. David Gaudu (Groupama-FDJ) 4:54:32
2. Gino Mader (NTT) +00:28
3. Ion Izagirre (Astana) +01:05
4. David de la Cruz (UAE Team Emirates) +01:05
5. Mark Donovan (Sunweb) +01:53

CLASSIFICATION STANDINGS

General Classification

1. Primoz Roglic (Jumbo-Visma) 64:20:31
2. Richard Carapaz (INEOS Grenadiers) +00:24
3. Hugh Carthy (EF Pro Cycling) +00:47

Points Classification

1. Primoz Roglic (Jumbo-Visma) 204
2. Richard Carapaz (INEOS Grenadiers) 133
3. Dan Martin (Israel Start-Up Nation) 111

King of the Mountains

1. Guillaume Martin (Cofidis) 99
2. Tim Wellens (Lotto Soudal) 34
3. Richard Carapaz (INEOS Grenadiers) 30