Castres' most recent home defeat was against Ulster last January and they fell to another Irish province here despite establishing a 14-0 lead and dominating the scrum.

A weakened Castres team ended the first quarter in full control as full-back Brice Dulin touched down to add to Scotland and Lions lock Richie Gray's opening try.

Jimmy Gopperth scored two tries in response, the second coming in first half injury-time, as Leinster closed the gap to 17-12 at the interval.

It was a real war of attrition in the concluding 40 minutes and Matt O'Connor's men gained vital momentum on the hour mark, courtesy of three Gopperth penalties and a drop goal from Rob Kearney on his 50th Heineken Cup appearance.

Flanker Jordi Murphy then claimed his first European try to put the result beyond doubt, while Castres capitalised on Sean Cronin's sin-binning to score a consolation try through Remi Lamerat in injury-time.

Having lost at home to Northampton Saints in the previous round, Leinster needed to bounce back in order to keep hold of top spot in the pool and remain on course for a quarter-final berth.

Castres were missing some notable names through injury - top-scoring scrum half Rory Kockott and back rowers Pedrie Wannenburg and Antonie Claassen chief amongst them - but their shadow side got off to a very strong start.

Neither 22 was threatened amid an early spate of knock-ons and turnovers, with Leinster opting to play into a stiff breeze and bright sunshine.

Luke Fitzgerald showed a neat step as he saw some initial ball, but Castres made the breakthrough in the ninth minute in a move launched by once-capped French international Ibrahim Diarra.

The tackled flanker got his hands free to send centre Lamerat weaving through some lacklustre Leinster challenges. He was brought down in sight of the posts, before Seremaia Bai scooped a long pass out for the waiting Gray to score in the left corner.

Television match official Derek Bevan confirmed the score which Cedric Garcia crisply converted, and the hosts drew further encouragement from two dominant early scrums - the second winning them a clearing penalty.

Breaks from Eoin Reddan and Jamie Heaslip, with hooker Cronin running a good line off the latter's shoulder, saw Leinster go close to responding, but a turnover from Diarra saw Castres clear the danger.

The excellent Diarra forced another turnover near halfway from which the French side sprung winger Remi Grosso into space on the left and with Rob Kearney drawn in, he passed inside for Dulin to finish off their second try.

Garcia's conversion left Leinster 14-0 adrift and with considerable ground to make up. Their forwards took up the baton, with Murphy held up short from a lineout maul.

From the resulting scrum, the Castres defence was caught off guard as Reddan passed for his half-back partner Gopperth to step clean through and score by the posts, with the New Zealander also converting.

Leinster's scrum was in trouble again late in the half and although goal-kicking scrum half Garcia missed a kickable penalty, he was on target from a more difficult position in the 39th minute.

However, the visitors - aided by a fine Fitzgerald run - got a timely boost when Gopperth shrugged off two tackles and stretched over under pressure from Gray to claim his second try. His conversion attempt went wide but Leinster were back within touching distance.

Lamerat provided a touch of attacking class to send Castres powering into the Leinster 22 on the resumption, but they failed to build on Piula Faasalele's pick from the base of a subsequent scrum.

Leinster were living dangerous as Lamerat's centre partner Bai bulldozed through and Daniel Kirkpatrick had to be brought down close to the posts.

Clawing back some much-needed territory, Leinster won a central penalty for some needless stamping by Garcia and the successful kick from Gopperth made it a two-point game.

Jack McGrath deserves a mention for his role in the province's comeback, with the loosehead prop responsible for four turnovers during his 60 minutes on the pitch.

Reddan soon sniped through on a break which led to a long range drop goal from full-back Kearney, moving Leinster ahead for the first time, and Castres coughed up another penalty which Gopperth nudged home.

Leinster were suddenly 24-17 ahead when a 63rd minute carry from McGrath's replacement Cian Healy - a late inclusion on the bench after an incredibly quick recovery from ankle surgery - set up Gopperth's third penalty goal.

As the game became more ragged, the visitors continued to prosper with Gopperth's stabbed kick just too strong for Fitzgerald in the left corner.

However, Leinster's overworked defence was tested to its limit after Cronin was yellow carded for a clear infringement at a ruck. With ten minutes remaining, the pool leaders still had work to do.

The Castres pack battered away in the Leinster 22 but the visitors, following a spell of desperate defending, countered for a brilliant third try.

Healy and Shane Jennings made quite an impact off the bench and the former cut inside two tackles and passed for Murphy to dive over in the right corner in the 77th minute.

Although the win was now beyond them, Castres' persistence was rewarded in the dying seconds when Lamerat scrambled over from a close-in ruck despite the presence of Ian Madigan and Murphy.