Joao Almeida (UAE Team Emirates) won the tough 203-km 16th stage atop Monte Bondone for his first victory in a Grand Tour.
The Portuguese cyclist crossed the summit finish just ahead of Thomas, who also picked up valuable bonus seconds.
Primož Roglič (Jumbo-Visma) was third, 25 seconds further behind.
Tuesday’s result meant Thomas (Ineos Grenadiers) moved back into the lead, 18 seconds ahead of Almeida and 29 in front of Roglic.
Jack Haig (Bahrain Victorious) was Australia’s best finisher, coming in 17th, 4:15 behind to leave him 18th overall, 10:58 adrift.
Thomas turns 37 on Thursday, three days before the race ends in Rome. The oldest Giro winner is Fiorenzo Magni, who was 34 when he won in 1955.
Tuesday marked the beginning of a brutal final week.
It was one of three of the last six stages that have been given the maximum difficulty rating of five stars.
There was more than 5000m of elevation and five categorised climbs along the route from Sabbio Chiese, including the top-category climb to the finish.
And it was on that climb to Monte Bondone that the race sparked into life.
Almeida attacked with less than seven kilometres remaining and Thomas made his move shortly after, bridging across to set up the battle for the stage win.
Primož, who had been in the leading group, could not go with him.
“[It was] a special victory, a dream come true,” Almeida, who climbed to second in the overall standings, said.
“I worked together with Thomas to put seconds between us and Roglič, but then my main goal was the stage win.
“I try to improve day by day to become the best version of myself.”
Thomas said it was a very tough day, with lots of climbs.
“I am happy with how it went,” he said after the stage.
“I found myself in front with Almeida, he was better in the sprint.
“I am not surprised by him, he is a very strong rider and a strong contender for the maglia rosa.”
Wednesday’s 17th stage offers a brief respite as the 195 km route from Pergine Valsugana to Caorle starts with a gradual descent before a long, flat finish which is likely to end in a bunch sprint.
AAP