Race leader Tadej Pogačar (UAE Team Emirates) attacked with just over eight kilometres remaining until the finish line and then surged again, reducing the front of the race to just the climbing trio of himself, Carapaz and Jonas Vingegaard (Jumbo-Visma).
Vingegaard recovered briefly in Pogačar's wheel before helping him set the pace, as the Danish rider saw the opportunity to move up from third to second with Rigoberto Uran (EF Education-Nippo) dropped, as well as distance the remainder of the GC rivals, with second to eighth on the standings starting the stage within two minutes of each other.
Carapaz refused to come to the front to do a turn of pace-making, he had all the same reasons to work as Vingegaard, having started the day just a second behind the Dane on the overall.
Despite Carapaz maintaining an eternal grimace of pain on his face he matched the multiple attacks of Pogačar as the Slovenian attempted to attack away for the win, then sat at the back and again saved his energy for one big assault with just over a kilometre remaining in the race. He launched and caught his rivals unaware, getting a gap initially.
Pogačar was able to cover the move and sit on the Ecuadorian's wheel and Vingegaard was able to fight back to the front of the race and pass Carapaz before the line, beating him by a second as Pogačar won the stage with his sprint to the line.
After the stage, Carapaz was left by the side of the road taking deep breaths hunched over his bike, but recovered to talk of his stage performance.
"The Tour is like a marathon and you don't have to give up until the last finish line," said Carapaz to Spanish news outlet AS. "We will not stop trying, even if the opponent does not give in to our rhythm.
"There is only one day left in the Pyrenees and the time trial; I must get the most out of myself."
That seems to suggest that Carapaz is thinking of attacking, he will certinaly need to take time on the superior time triallist Vingegaard if he wants to usurp the 24-year-old's position on the general classification.
On the tactics in the final, Pogačar said in his winner's interview that he knew Carapaz was bluffing when he wouldn't pull through to work and Vingegaard similarly had suspicions when he was watching his adversary.
“I was thinking it [about Carapaz]," said Vingegaard, "because every time we were looking back, even when we were going easy, he was looking like he was suffering a lot, I was thinking that he was going to do a good attack.
"When he attacked, I couldn’t go with him, and I just went at my own pace. Luckily, I could come back and get second in the end."
The Tour de France continues with Stage 18, another big day in the mountains, with the peloton summiting the dual hors categorie climbs of the Col du Tourmalet and the Luz Ardiden over a total stage distance of just 129.7 kilometres. Watch the racing action from 2130 AEST on SBS, SBS OnDemand and the SKODA Tour Tracker.