Warrington kept up the pressure on engage Super League leaders Leeds thanks to a last minute try from second row Louis Anderson.
Bottom club Castleford were 31-30 ahead until brothers Mark and Martin Gleeson linked to put Anderson in for a dramatic last-gasp winner.
It was tough on the promoted Tigers who recovered superbly from 12-0 down after 16 minutes.
They were inspired by teenager Joe Westerman who grabbed a hat-trick of tries.
Warrington, who were still without injured Australian scrum-half Michael Monaghan, quickly took command.
Paul Rauhihi was hauled down just short and Matt King was held up over the line in an early Wolves onslaught.
They went ahead in the sixth minute when Lee Briers cleverly made the opening for Ben Westwood to score the opening try that Briers goaled.
Injury-hit Castleford rallied strongly and winger Adam Fletcher was bundled into touch near the corner after good handling by Brent Sherwin and Westerman.
However, Warrington continued to look the sharper side and doubled their lead in the 16th minute when full-back Stuart Reardon twisted his way through to score after John Clarke and Vinnie Anderson paved the way. Briers converted to make it 12-0.
Warrington's Vinnie Anderson was sin-binned in the 23rd minute for holding down Castleford's Kirk Dixon after Anderson's pass was intercepted by Sherwin who made a 60-yard break.
The Tigers capitalised on the extra man to level the scores with two tries in three minutes from Westerman who added both conversions.
Westerman powered over for his first score after Kevin Penny failed to deal with Luke Dorn's high kick and struck again when Sherwin put him in for his second.
Warrington regained the lead on the stroke of half-time when Martin Gleeson went over from Westwood's pass and Chris Hicks added the goal to give the visitors an 18-12 lead.
Castleford were level again when Ryan McGoldrick and Peter Lupton handled to send in Richard Owen and Westerman tagged on the goal.
The game swung back Warrington's way when Mark Gleeson capitalised on strong play by King to score a 53rd-minute try.
The Wolves scored again two minutes later when Louis Anderson put in Vinnie Anderson and Hicks kicked his third goal to give them a 30-18 advantage.
But Castleford refused to lie down and struck back with two tries.
Lupton finished a cross-field move before Sherwin's long pass saw Westerman complete his hat-trick.
With seven minutes remaining Westerman tied the scores at 30-30 with his fifth goal when he kicked a penalty after Sherwin was obstructed after putting in a kick.
Sherwin looked to have won it for Castleford with a 25-yard drop goal with three minutes remaining but then came Anderson's last-gasp score.