Thomas, who came into the race off the back of the Tour de France, had broken away from the lead group on the final lap and had enough time advantage to change the wheel and resume his charge for the line with a 20-second lead.
New Zealand's Jack Bauer edged out England's Scott Thwaites to claim the silver medal as wet and wild conditions made life difficult in Glasgow.
"I never expected it," said Thomas, who also won time trial bronze earlier in the week and is the first man from Wales to win a Commonwealth Games cycling gold.
"Coming off the Tour de France, I was tired at end of that. I thought it would be a massive challenge to get a result here but the motivation was there.
"I never expected to win. It was more out of pride for Wales. It's a massive team effort. All the boys have been helping me out."
"After coming out of the Tour I'm shattered. I really just wanted to come and ride for Wales."
© Sportsbeat 2014
- Sports & Recreation
- Tour de France
- Jack Bauer