Lee Hopkins (left) grabbed Quins' opening try
Harlequins (18) 24
Tries: Hopkins, McLinden 2, Randall
Goals: Paul 4
Castleford (4) 16
Tries: Manu, Huby, Viane
Goals: Brough 2
Harlequins ended a run of three Super League defeats with a priceless home win to ease their relegation worries.
An early Lee Hopkins try and two scores from captain Mark McLinden put the hosts 18-4 up by half-time, Willie Manu replying with one for the Tigers.
Chad Randall grabbed Quins' fourth try on the resumption, with Henry Paul converting all four scores.
Craig Huby and Gray Viane crossed for further Cas tries but it was not enough to stop Quins securing victory.
The win lifted them three points above Wigan and Catalans at the bottom of the table into seventh, above Castleford on points difference.
Harlequins: McLinden, Smith, Gafa, Lucky Luisi, Bradley-Qalilawa, Paul, Weisner, Mills, Randall, Heckenberg, Purdham, Hopkins, Mbu.
Replacements: Tookey, Budworth, Lolohea, McCarthy-Scarsbrook.
Castleford: Platt, Pryce, Viane, Shenton, A. Fletcher, Brough, Lupton, Sculthorpe, Henderson, Nutley, R. Fletcher, Ward, Roarty.
Replacements: Fa'aoso, Manu, Huby, Handforth.
Referee: R Laughton (Barnsley)