The reigning world champion in time trial had a lead during the entire final ascent and descent of the 200.5-km stage from Lourdes to Laruns.
Two stages to go, Roglič is in third place overall, having a 13-second advantage ahead of Chris Froom of the UK.
Geraint Thomas of the UK kept the overall lead ahead of Tom Dumoulin of the Netherlands, who trails the leader two minutes and five seconds. Roglič is 29 seconds behind Dumoulin.
On Saturday, the best cyclists in the world will take on a 31-km time trial, while the 2018 Tour de France will conclude with a 116-km stage from Houilles to Paris.
"What can I say ... I'm very happy. It's crazy. The feeling is really nice. It's obvious that I had the best legs today. I tried several times and I managed to get rid of the opponents during the descent," Roglič said after winning the stage.
Asked what he expected from Saturday's time trial, which pundits believe is "made" for him, he said that "time trial is the same for all. We all start from zero. A new day is tomorrow, and I will have to be focused again, but I will certainly give my best."