Watch all the best , with the Tour de France, Tour de France Femmes and much more.
Roglič started the day 26 seconds in arrears of incumbent race leader Thomas, and it looked like the Slovenian would have a tough test ahead of him from early on as he was just 2 seconds in front of his Welsh rival at the first check point.
Both riders had bike changes at the bottom of the steep climb to Monte Lussari, with Thomas also changing his helmet, a few seconds extra in the changeover to provide a benefit on the climb. However, Roglič continued to gradually expand his lead to 15 seconds by halfway up the ultra-steep seven-kilometre climb up the narrow path.
Then, misfortune struck the Slovenian, his chain bouncing off his front derailleur over a bump, the three-time Vuelta a Espana champion having to stop to get it back on. He then received a hurried push from a mechanic that saw Roglič baulk again, before a second push from the mechanic and a fan on the roadside got him going again on the steep slopes.
What could have been the end of Roglič’s push for overall honours instead seemed to spur him on, his the hordes of Slovenian fans by the side of the road cheering him on. Thomas was clearly finding the going tougher and tougher as he reached the upper slopes of the climb, and the gap continued to grow, even with the mechanical of his rival.
Roglič set the fastest time at the finish, and could only wait for Thomas to come in, a clearly exhausted pink jersey holder coming over the line for second on the day, but 40 seconds adrift of Roglič, who took control of the general classification by 14 seconds over Thomas.
"Amazing, eh? It's not at the end about the win itself, it's about the people, the energy was incredible, these moments to live and to remember," Roglič said.
“I mean, I had the legs, the people gave me extra Watts, so we're just trying, we're enjoying this."
Thomas said he was “devastated” after coming so close to victory, but he admitted that with 1,500 metres left on one of the toughest mountain time trials in recent memory, he could feel his legs failing him.
“To be honest, Primož deserved it. He had a mechanical, but he put 40 seconds into me, so chapeau to him,” Thomas said. "I guess it's nice to lose by that much, it would have been worse to lose by a second or two. At least he smashed me."
João Almeida (UAE Team Emirates) finished third on the stage and solidified his third overall on the standings, retaining his position in the white jersey as the best young rider at the race.
The Giro d’Italia 2023 concludes with a shorter 126-kilometre stage around Rome, a later start and finish for the final stage, with the race broadcast starting at 11.05pm AEST and presentations expected to conclude at 3.25am AEST.