Primoz Roglic teetered in the final ascent but was poised to retain his Vuelta title after keeping the overall lead in the penultimate stage, a 178.2-km mountain trek from Sequeros won by France's David Gaudu on Saturday.

The Slovenian, who lost the yellow jersey on the Tour de France in the final time trial in September, was dropped by second-placed Richard Carapaz in the last climb, a 11.4-km effort at an average gradient of 7.1%, but hung on to top spot.

Ireland's Dan Martin finished 18th on the stage and holds on to fourth overall in the general classification after 17 stages. Sam Bennett finished 142nd on the stage.

Going into Sunday's 18th and final flat stage to Madrid, Roglic, who had a 45-second advantage before the start in Sequeros, leads Ecuador's Carapaz by 24 seconds and Britain's Hugh Carthy by 47 seconds.
Gaudu, who claimed his second stage win, broke into the top 10 in the general classification.

Roglic seemed in total control when Carthy was the first to attack with about 4km to go but a brutal acceleration by Carapaz three km from the line left the Jumbo Visma rider stuck to the tar.

As the light faded on the Alto de la Covatilla so did Roglic's hopes with his virtual overall lead being cut to 18 seconds.

But Caparaz plateaued and Roglic dug deeper in the last kilometre to edge closer to putting his Tour de France heartbreak behind him.

Almost three minutes before that the 24-year-old Gaudu had crossed the line for a solo win that gave him eighth place in the general classification on his first grand tour as a team leader with Groupama-FDJ.