The hosts seemed to have the game in the bag when they led 23-6 soon after half-time, but Trinity refused to give in and two converted tries in the final quarter set up a tense finale - the final hooter sounding after Wakefield had forced a drop-out with a kick on the last play which Castleford just managed to scramble dead.
It was Tigers' first win at home in seven games since fans were allowed back into stadiums in May and they narrowly desrved the victory, though Wakefield deserved great credit for a spirited display.
The hosts attacked Trinity’s right side relentlessly in the opening exchanges and went ahead after eight minutes in spectacular fashion through a diving finish by Greg Eden from Niall Evalds’ pass.
Danny Richardson converted from the touchline and then, just four minutes later, added another goal after he had provided a lovely short pass to send Oliver Holmes crashing over just to the left of the posts.
Trinity quickly hit back, following two penalties near Tigers’ line, when Brad Walker kicked through and Tinirau Arona touched down. Mason Lino’s conversion made it 12-6 after a blistering blistering opening 16 minutes.
Castleford scored next, eight minutes later, when the visitors were caught offside and Richardson took the two.
Moments later, he was having a 10-minute sit down after being sin-binned, along with Lino, after a set-to between the rival number sevens.
Wakefield received the penalty and almost scored in the resulting set when Kelepi Tanginoa forced his way over the line, but Jesse Sene-Lefao held him up
That was a crucial intervention as Castleford, after being under heavy pressure, counter-attacked to score a well-worked try, Derrell Olpherts going over against his home city club from a pinpoint pass by Evalds.
Gareth O’Brien couldn’t add the extras, but Richardson cleverly extended Tigers’ lead to three scores at the break with a drop goal in the final seconds of the half.
He turned provider seven minutes after the resumption with a looping pass which created a second - unconverted - try for Eden to extend the hosts’ lead to 23-6.
Tom Johnstone pulled a try back on the hour with a brilliant finish, catching Jacob Miller’s kick and accelerating through the defence to give Lino a simple conversion.
A knock-on by Evalds after Richardson had split the defence kept Wakefield in it and they set up a grandstand finish when Eden palmed Lino’s kick to Kershaw behind Castleford’s line.
Lino landed the conversion from wide out to cut the gap to five points with as many minutes left, but the visitors could not find a winner despite desperate late pressure.
Tigers' victory was their third in succession and keeps alive their hopes of sneaking into te Betfred Super League play-offs.