Castres have only lost once at the Stade Pierre Antoine once this season but went behind early courtesy of a Rhys Priestland penalty and a try from No 8 Matt Gilbert.
South African scrum-half Rory Kockott clawed Castres back into the game with two quick penalties after the Scarlets were found guilty of infringements at the breakdown to make it 8-6 to the visitors at half-time.
The Scarlets lost Priestland with what looked like an ankle injury at the start of the second half after he twisted in a tackle and limped off the field before flanker Aaron Shingler ran 80metres for a superb interception try.
The hosts levelled the scores with a try by replacement Yannick Forestier, converted by Romain Teulet, to make it 13-all but fly-half Stephen Jones sealed the victory with a penalty in the dying moments.