Chris Froome took a major step towards his fourth Tour de France title despite his lead being cut on the Col d'Izoard.
Frenchman Romain Bardet clawed back four seconds in bonus time as he pipped Froome to third place on stage 18, won by Warren Barguil, but the Briton emerged from the final mountain test of the race with a 23-second cushion in yellow.
With a relatively flat stage to Salon-de-Provence to follow on Friday before a time trial in Marseille that should suit Froome, his rivals are all-but out of opportunities to deny him.
"I wouldn't say it is quite won yet but certainly the toughest part of the Tour with the Alps and the Pyrenees is done now," Team Sky's Froome said.
"I'm pretty happy to have got through the Alps much better than in previous years because I've always struggled in the Alps."
Bardet sits second overall with Rigoberto Uran third, 29 seconds down, and it is perhaps the Colombian who poses the bigger threat given his track record in time trials.
That said, the Cannondale-Drapac rider conceded 61 seconds to Froome in the opening time trial in Dusseldorf almost three weeks ago, compared to 39 by AG2R La Mondiale's Bardet.
"It's a really close race for sure," Froome added. "Hopefully if the first time trial in Dusseldorf is anything to go by then I will have the upper hand on the rest of the GC guys. But it's still very close and anything could happen."
Froome had tried his best to ditch his rivals in the final kilometres of the climb up to Izoard.
Sky team-mate Mikel Landa, fourth overall, was sent up the road as a decoy, forcing Bardet into an attack with three kilometres left.
But Froome quickly caught and passed Bardet and then dropped him on the short descent at Casse Deserte, two kilometres from the top.
For a moment it appeared the fight for yellow was over as he swiftly raced away from the others, but the distances were deceptive and instead the decisive move came when Bardet attacked again with 400 metres left.
But even with the time gained, Bardet - who finished as runner-up to Froome in last year's Tour - appeared to accept his fate.
"I risked everything," he said. "I have nothing to regret. Now we have the time trial but the Tour is already a success. We confirmed what we did last year, we went a step further."
Barguil raced away from the main group of contenders with six kilometres left and beat the last surviving member of the breakaway, Darwin Atapuma, to take his second stage win and underline his superiority as king of the mountains - a classification he will win providing he safely makes it to Paris.
The 25-year-old has enjoyed an outstanding Tour after a miserable time with injuries in the last 18 months.
A contender for yellow in previous years, he came to the Tour with a free hand and has made it pay with two stage wins and the polka dots - matching the success of his Sunweb team-mate and room-mate Michael Matthews who has two stage wins and the points leaders' green jersey.
"I'm living inside my dream at the moment, it's crazy," Barguil said. "After all my bad luck I can show another side to everybody."
But others suffered on the climb. Italian national champion Fabio Aru was dropped again, conceding over a minute as the former yellow jersey in this race slipped to fifth on general classification, behind Landa and almost two minutes adrift of the race lead.
Irishman Dan Martin was active in forcing the pace on the Izoard, and finished within 19 seconds of Bardet and Froome to retain sixth place overall.