|Salford Red Devils (10) 22|
|Tries: O'Brien, Dobson, Caton-Brown Goals: O'Brien 5|
|Castleford Tigers (12) 18|
|Tries: Webster 2, Dorn Goals: Gale 3|
Gareth O'Brien boosted Salford's top-eight hopes with two late penalties to overcome Castleford, who suffered a heavy injury toll in defeat.
Castleford led 12-10 at the break with Jake Webster going over twice, while O'Brien and Michael Dobson grabbed the hosts' scores.
Luke Dorn added a third Tigers effort, before Webster became the third Castleford player forced off injured.
Mason Caton-Brown's try and the boot of O'Brien sealed victory.
Castleford's fourth Super League defeat in five games leaves them seventh in the table and needing at least one win from their remaining three regular season games to seal a spot in the Super 8s.
For Salford, a side that owner Marwan Koukash admits have been a failure since his takeover in 2013, the win moves them up to ninth and to within four points of eighth-placed Widnes, who face bottom-side Leeds Rhinos on Sunday.
The Red Devils next take their fight to the court room, when their appeal against a six-point deduction for breaching salary cap regulations in 2014 and 2015 is heard on Wednesday.
On the field, they left their fight back late against a gritty Castleford side that lost winger Joel Monaghan to injury inside five minutes.
Despite the setback Webster opened the scoring for Tigers with a bustling run, only for O'Brien to respond in similar fashion and Dobson to put Salford ahead with a try on his 200th Super League appearance.
Dorn produced a fine one-handed offload inside to put Webster over again before the break and then went in himself after the interval.
However, with forward Mike McMeeken followed off the field by Webster, Salford eventually managed to overcome the stubborn visitors.
Salford head coach Ian Watson:
"It's always been our aim to get in the top eight and while it's still possible, we want to keep aiming there. We feel we should be there in our own right.
"Obviously it's a big week for us because we've got the hearing to see if we get the points back or not.
"Gaz [O'Brien] is quite a relaxed character and, in situations where you need him, he generally comes up with the goods. We've a great bunch of guys who are very competitive and we give ourselves a chance in every game.
"We just needed to learn to manage the game better and today I thought we managed it really well. We've executed really well and come through the other side, which is a big one for us."
Castleford head coach Daryl Powell:
"It's another tight one where we've come out the wrong side of the scoreline. I thought we should have won, to be honest, but it was a pretty courageous effort based on what happened to us.
"To lose your starting back row, a centre and winger makes it really hard. We had one sub for a fair chunk of the game and ended up with Larne Patrick in the centres.
"I think we've got to be a bit more durable under pressure. We've just got to stick together and dig in. We've got three games left before the split and some real tough ones."
On links to former player Rangi Chase coming back to Wheldon Road:
"It's speculation. I haven't anything to say about it."
Salford Red Devils: O'Brien; Caton-Brown, J Griffin, Sa'u, Johnson; Lui, Dobson; Kopczak, Tomkins, G Griffin, Murdoch-Masila, Jones, Flanagan.
Replacements: Hauraki, J Walne, Kenny, A Walne.
Castleford Tigers: Dorn; Monaghan, Crooks, Webster, Flynn; T Holmes, Gale; Tickle, McShane, Patrick, Moors, McMeeken, Massey.
Replacements: Milner, Millington, O Holmes, Springer.
Referee: James Child (RFL)