Chris Froome survived a mechanical and a crash to keep hold of his red jersey, but his lead at the Vuelta a Espana was cut to 59 seconds.
The Team Sky leader dropped 20 seconds to closest challenger Vincenzo Nibali (Bahrain-Merida), who finished in the main group of general classification contenders on stage 12.
Trek-Segafredo's Alberto Contador, who is ninth in the GC standings, gained 22 seconds on Nibali and the rest of the general classification contenders.
Lotto Soudal's Tomasz Marczynski attacked on the final descent to take stage victory ahead of Omar Fraile (Team Dimension Data) and Jose Joaquin Rojas Gil (Movistar), as the break stayed away.
But down the road, the GC battle was springing to life.
Contador and Nicolas Roche (BMC) attacked on the final climb, with the Spaniard surging clear and enjoying an advantage of 20 seconds from the Team Sky-led peloton.
But on the descent into Antequera, Froome suffered a mechanical and, after switching bikes, quickly took a tumble as he attempted to take a corner.
Sky dropped Wout Poels and Mikel Nieve back to try to help him limit his losses, and the pair managed to keep the Briton in red.
They trailed Contador by more than a minute at one point but recovered time in the final kilometers as Froome remained on course to become the first rider since 1978 to win the Tour de France and the Vuelta in the same year.