Harlequins took a giant stride away from the engage Super League drop zone as they ended a three-game losing streak with a dogged win over Castleford.
Quins nearly enjoyed a dream start after 10 minutes following some Mark McLinden magic under the posts - but the strong Castleford defence held firm one yard out.
Tony Rea's men eventually struck first on 17 minutes.
Lee Hopkins provided the magic, taking the ball on the Tigers' 40-yard line and evading two Castleford tacklers for a straightforward run over the line. Quins newboy Henry Paul made no mistake with the conversion.
The hosts stretched their lead in the 26th minute as Hopkins unloaded in the tackle to a charging McLinden, who made no mistake from close range - Paul again provided the extras with his second conversion.
Castleford hit back when substitute Willie Manu found himself unchallenged on the left flank and raced into to score, handing the visitors a much-needed lifeline.
Quins extended their advantage before the break when McLinden received the ball on the Tigers' 30-yard line, powering over for his second touchdown of the half, which Paul again converted to make the score 18-4 at the break.
Just a point off the bottom of the table prior to kick-off, Rea was desperate for a win and Quins responded with an early second-half try.
Home pressure paid off 15 minutes after the restart as Joe Mbu passed to Chad Randall five yards out and the former Manly hooker took full advantage. Paul once again kicked to perfection.
The Tigers hit back almost immediately to set up nervous finale, with Craig Huby touching down from close range. Brough made no mistake with his conversion this time.
Castleford put Quins under pressure with 10 minutes left thanks to a try by Gray Viane - the centre marking his new two-year deal signed earlier this week.
But despite frantic late pressure by the visitors, Quins held on for a crucial victory.