Having levelled the scores after the hooter at Hull KR last month, the tables were turned on Castleford when Salford scored on the final play and a conversion with the final kick sent the tie into sudden death.
Salford had first use of the football, but Paul McShane charged down Kevin Brown's one-point attempt and then managed to grab the ball, setting up position for O'Brien to again boot Castleford through.
O’Brien went from villain to hero, having been sin-binned in the closing stages of normal time.
With Liam Watts following him, Castleford were down to 11 men briefly and had only 12 on the field at the end.
McShane was outstanding for Tigers, providing the final pass for two of their three tries.
Castleford will face Warrington Wolves - the side their coach Daryl Powell joins next year - in the last-four on June 5, while Hull play St Helens in the other semi-final.
Salford survived fierce Tigers pressure before grabbing the first try, after 15 minutes.
Brown’s kick was knocked by Derrell Olpherts into Niall Evalds, the ball came loose and Harvey Livett touched down.
Video referee Liam Moore confirmed Ben Thaler’s original decision of try and Livett added the extras.
Salford then forced back-to-back drop outs, but Danny Addy knocked on trying to worm his way over from acting-half.
A penalty carried Tigers upfield, they received a six-again and Daniel Smith, who had been on the field a matter of seconds, crashed over from acting-half McShane’s pass.
Danny Richardson converted to level the scores after 24 minutes.
Liam Watts got over the line for Cas, but knocked on - as confirmed by the video ref - and within moments Salford were back in front.
Livett was again the scorer, taking James Greenwood’s pass and skipping past Olpherts for a try he also converted.
That was five minutes before the break, but Tigers made Salford pay for an error and penalty to pull level on the final play of the half.
Video referee Moore ruled Ken Sio had knocked Michael Shenton’s pass forward before Jordan Turner fumbled it over the line.
So the ball was handed back to Tigers and, with 28 seconds of the half remaining, Watts created some space for Grant Millington and his pass sent Peter Mata’utia over, Richardson landing the angled kick.
Cas missed a chance to go ahead when Shenton lost the ball in Sio’s tackle just short of the line, from Richardson’s kick, but the skipper made no mistake on the hour.
Pau McShane created the try by going blind for acting-half and then shipping out an offload which a stumbling Shenton did well to hang on to before sliding over at the corner.
O’Brien, who had replaced Richardson 10 minutes earlier, booted a touchline conversion, but with 14 minutes left he was sin-binned for obstruction on Chris Atkins as the Salford man chased Tui Lolohea’s kick.
In the next set Brown got over the line, but Thaler and video ref Moore ruled he had been held up - brilliantly - by Tigers’ last-ditch defence.
Before O’Brien returned, Watts was also yellow carded for a foul on Elijah Taylor and Lee Mossop was held up over the line while Tigers were two players short.
With just a minute left, Cas conceded a penalty close to Salford’s line and, 12 seconds from time, Mossop crashed over setting up Livett’s conversion, after the hooter, to square the scores.