Castres 13 (6)
Voyce's fine try early in the second half made all the difference
Pens: McIntyre 2
Wasps 16 (9)
Pens: King 2
Wasps secured a home tie in the Heineken Cup quarter-finals as they clinched a rare away win in Europe.
Alex King kicked the visitors into an early 9-0 lead before two Cameron McIntyre penalties reduced the gap to 9-6 at the break.
Tom Voyce's fine finish, converted by King, gave Wasps a 10-point advantage.
Castres hit back almost immediately through Pascal Pape's converted try but Wasps upped their performance again and some brave late defence saw them home.
Castres looked threatening in the early stages and twice threatened to cross the Wasps line but they found themselves trailing 9-0 after 12 minutes as King landed two penalties and a drop-goal for Wasps.
The injustice of it all stung the French side and they hammered their way back into the game, a series of powerful thrusts leading to two penalties which McIntyre duly slotted.
The crucial period came either side of half-time.
First Castres were forced to bring on Scottish fly-half Gordon Ross just before the break and his first contribution to the game was to fail with two long-range penalties.
Then, eight minutes into the second half, Wasps counter-attacked after Simon Shaw halted an incisive Castres break and Fraser Waters' pass was deflected into the hands of Voyce, who beat Laloaoa Milford one-on-one before crossing under the posts.
King slotted the conversion to make it 16-6 but Wasps managed to hold out for just six minutes as Pape was driven over from a line-out.
Ross' conversion trimmed the gap to three points once more but it was only in the final moments that they threatened again.
Castres spent most of the final five minutes deep in the Wasps 22 but some combative defence, led by Lawrence Dallaglio, saw the visitors hold out.
In the other game in the pool Perpignan came to life in the second half to turn a 14-10 lead against Treviso into a 45-25 win and clinch second place in the group.
Wasps hooker Raphael Ibanez:
"This is a great result because it is a long time (2004) since Wasps qualified for the quarter-finals.
"We expected a really tough game today and that is what it was. But we were really focused, we didn't try to force things and we played with composure and experience.
"We needed to be really strong on our goal-line and that was really important at the end. It just shows the team spirit."
Castres: Teulet; Milford, Kefu, Christophers, Peyras-Loustalet; McIntyre, Laussucq; Hoeft, Giorgadze, Saayman, Pape, Nallet, Vooslo, Tabacco, Manta.
Replacements: Terrain, Castex, Capo Ortega, Bias, Marticorena, Carballo, Ross.
Wasps: Cipriani; Lewsey, Waters, Waldouck, Voyce; King, Reddan; Payne, Ibanez, Vickery, Shaw, Palmer, Worsley, Rees, Dallaglio.
Replacements: Ward, Bracken, Haskell, Purdy, Amor, van Gisbergen, Leo.
Referee: A Lewis (Ireland)