Paul Sykes snatched two precious points for Wakefield with a last-gasp drop goal in a thriller against St Helens.
Wakefield led at the break thanks to tries from Lee Smith, Andy Raleigh and Danny Kirmond's brace, with Tony Puletua, Francis Meli and Paul Wellens replying for Saints.
Smith and Kyle Wood went over for Trinity after the interval in addition to Wellens' second and Meli's treble.
Sykes and Tommy Makinson added four kicks each for their respective sides.
It took Saints just 27 seconds to open the scoring, after Meli returned the kick-off with a thrilling break down the left before offloading to Puletua who powered in despite the Wildcats' best efforts.
Wakefield responded well, trapping Meli in-goal after Tim Smith's kick bounced awkwardly and from the responding set the ball was worked out to the left and Mathers's ball found Smith to crash over for his third try of the season, and Sykes converted successfully to give the hosts the lead.
Having survived a break by Lance Hohaia when Puletua spilled, Wakefield added to their tally when a clever reverse kick through by Smith was pounced on by Raleigh.
Saints came back with a score of their own, Flanagan running the hard yards, and when the ball popped out from dummy half on the last, Jonny Lomax slipped a kick through for Meli to touch down, and Makinson again missed the chance to add the extras.
Indiscipline by Saints handed the Wildcats a set of six inside their opponents' 20 but Ben Cockayne was unable to react to Sykes's grubber and the visitors survived.
However Wakefield were playing some excellent football and made the most of a penalty against Michael Shenton to work in skipper Kirmond following a slick passing move from Tim Smith and Sykes, who kicked his third goal of the half.
Richard Agar's side were flowing with confidence and after Frankie Mariano's drive lifted the crowd, the ball was worked right and Kirmond ran onto another intelligent kick by Smith to burst through the gap to score his second of the game.
Saints did add a try just before the break, Makinson slalomed his way close to the line, and from the play-the-ball, a blindside pass from Lomax found Wellens, who wriggled out of a tackle to dive over with five to go.
In contrast to the opening period defences were on top at the start of the second and it took 10 minutes for the first try of the half that went the visitors' way.
Andrew Dixon ripped through a gap on the Wildcats right for Saints and his pass, albeit with a hint of forward, found Meli on the left with a clear run to the line and he touched down after initial hesitation to bring the deficit to two.
The outstanding move of the game took Saints ahead for the first time since the opening minute.
Roby made yards with a scuttling run, and when Lomax offloaded to Gaskell, his beautifully disguised inside pass gave Wellens the angle to sneak through for his second score.
Such was the topsy-turvy nature of the game, two minutes later Wakefield were back in it.
A super break by Ben Cockayne took Trinity up to halfway, and from the play-the-ball, Smith was released to take the Saints defence on the outside from 30 metres and dart in at the corner.
Wakefield continued to push, and were rewarded when substitute Wood picked up from inside the 20 and blasted through the gap to stun the Saints defence and restore the lead.
Meli snapped up his treble, making the most of Flannery's pop pass to drive in from 20 out, and Makinson was on the mark with his kick to again tie the scores.
Sykes missed his drop goal attempt with three to play as the tension, as did fellow half-back Smith momements later, but the on-loan Bradford man made sure with his second attempt on the hooter to snatch the two points.
VIEWS FROM THE DRESSING ROOMS
Wakefield coach Richard Agar:
"Eighth spot is up for grabs, for sure.
"I don't look at the table too much but I'm aware of our points tally and where we are in the league.
"Hull KR is without question the biggest game of the season next week, but even if we win that, we've still got to win some more games after it, but momentum is with us, and we've put ourselves in with a real shout of getting into that top eight."
St Helens caretaker coach Mike Rush:
"I didn't think we were great, sometimes you can judge enthusiasm and mental state on your kick chases, and ours were poor.
"We should have had Ben Cockayne tackled in goal, but he breaks away and two tackles later they score.
"They worked that littler bit harder and wanted it a little bit more than us."
Wakefield: Mathers, Fox, Cowling, L. Smith, Cockayne, Sykes, T. Smith, Amor, Ellis, Raleigh, Lauitiiti, Kirmond, Washbrook.
Replacements: Johnson for Amor (19), Wood for Ellis (45), Wilkes for Raleigh (31), Mariano for Lauitiiti (24).
St Helens: Wellens, Makinson, Shenton, J. Jones, Meli, Hohaia, Lomax, Perry, Roby, Laffranchi, Puletua, Flannery, Flanagan.
Replacements: McCarthy-Scarsbrook for Perry (21), Clough for Laffranchi (24), Dixon for Puletua (28), Gaskell for Flanagan (30).
Ref: T Alibert (Toulouse).