Revenge for Wildcats as Tigers lose at Magic Weekend
Wakefield's win enabled them to leapfrog Castleford into 11th place in the table.
The Tigers thought they had snatched victory when substitute forward Nathan Massey went over three minutes from time but the effort was disallowed by video referee James Child for offside.
Tim Smith then immediately went over for the Wildcats' sixth try to clinch matters.
It was Australian scrum-half Smith's second try since he made his Wakefield debut three months ago.
Castleford were hoping for redemption following their Super League record 70-12 hammering at Hull KR, after which they issued a public apology, and their whole-hearted efforts will have won back much of the supporters' trust.
Nobody tried harder than Rangi Chase, the reigning Man of Steel who made a big impact on his return from a three-match ban, setting up three of his side's five tries but gifting two to his opponents.
The Tigers made the perfect start, scoring the game's first try before their opponents had touched the ball, Chase getting centre Jordan Thompson through a gap in the Wakefield defence for a try in his third successive match.
Kirk Dixon's goal made it 6-0 and winger Rhys Williams was inches away from scoring on his debut when he was hauled down short of the line but the Tigers' deficiencies quickly re-surfaced as they conceded two tries in a four-minute spell.
Chase's pass was intercepted by Wildcats centre Vince Mellars, who held off all pursuers on an 80-metre sprint to the line, while full-back Richard Mathers, who is on a season-long loan from Castleford, jinked his way over from close range.
Tigers forward Stuart Jones, enjoying a rare outing at hooker, went over from dummy half for his side's second try but two handling errors from Williams put his side under pressure and Wakefield made it tell when second rower Steve Southern touched down Smith's grubber kick.
The sides then traded further tries as the soaring temperatures began to take their toll.
Winger Nick Youngquest followed up Chase's high kick to touch down but a Chase fumble deep inside his own half gifted Wakefield a glorious attacking position and they duly scored a fourth try with Smith's short pass getting loose forward Danny Washbook over.
Chase immediately made amends by offloading from the tackle for Danny Orr and Grant Millington to work second rower Oliver Holmes over for the Tigers' fourth try.
While Paul Sykes kicked his fourth goal from as many attempts for the Wildcats, Dixon succeeded with just two of his four kicks to leave his side trailing 24-20 at the break.
Defences improved in the second half but the errors continued, although Youngquest was particularly unfortunate when the ball took a wicked bounce from Smith's kick on halfway and went over his head to gift Wakefield winger Peter Fox a try.
Sykes lost his 100% record with the boot and Castleford received a lifeline when winger Ben Cockayne scythed through their defence after collecting Chase's kick and reached the corner but was unable to ground the ball after Owen's valiant last-ditch tackle.
Orr then set up a grandstand finish when he cut through for a solo try 11 minutes from the end which he converted himself to cut the gap to just two points but the Wildcats hung on and Smith's late effort ensured a memorable victory.