Jumbo-Visma's Roglic overcame a mechanical issue to win the brutal mountain time trial by 40 seconds as Ineos Grenadiers rider Thomas' title challenge evaporated on the steep slopes of Monte Lussari in the penultimate 20th stage of the race.
"It feels amazing. It's incredible," Roglic said. "My chain dropped but I put it back. I could have lost everything but it's part of racing.
"The crowd gave me some extra watts and I was enjoying the atmosphere and the energy around the event. One day to go. The course is a bit technical. It's not over until it's over, but it looks good."
The Slovenian led at the first timecheck and extended his lead over Thomas to 16 seconds halfway up the climb, before hitting a pothole and dropping his chain.
He lost time and momentum while changing bikes but was able to regain his composure and clock the best time of 44 minutes and 23 seconds, turning his 26-second overall deficit into a 14-second lead over Thomas.
Joao Almeida of UAE Team Emirates finished third, 42 seconds behind Roglic.
Saturday's victory will feel like redemption for Roglic, who lost the 2020 Tour de France on the final competitive day of racing, a time trial in which he gave up his lead - and the overall race victory - to fellow Slovenian Tadej Pogacar.
Roglic, who won the Vuelta a Espana in 2019, 2020 and 2021, will take a 14-second lead over Thomas into Sunday's largely processional 135-km flat run through the streets of Rome.
"I could feel my legs going 1.5km from the top of that climb," Thomas said. "I don't want to sound like I'm making excuses but I just didn't feel like I had that grunt.
"I guess it's nice to lose by that much rather than a second or two, because that would be worse. At least he smashed me. To be honest, Primoz deserves that. He had a mechanical and still put 40 seconds into me, so chapeau to him."