The 36-year-old Greipel chased down Australia's Caleb Ewan to cross the line first at Pembrey Country Park after a 175km stage which also included Thomas's Sky team mate Chris Froome.
Thomas finished safely in the peloton after finding the pace too hot on the final climb.
"I had to give it a go, being on home roads and so close to where I grew up. I knew the climb but once I went I was thinking: 'What have I done?'," said Thomas, who is to have Newport's velodrome named after him.
News that makes sense
Your trusted source for staying up-to-date with the world around you. Get free daily news updates and analysis, straight to your inbox.
"It was nice to have a dig but I don't have the legs to finish it off."
It was Greipel's sixth stage win in the Tour of Britain.
(Reporting by Martyn Herman, editing by Ed Osmond)
