Trinity led by 10 points at the break, went 10 behind with 17 minutes left, edged back in front two minutes from time and then held on when Salford knocked-on over the line on the final play.
Wakefield seemed to be well in command at the break, when they led 12-2.
It should have been more as Salford had Lama Tasi and Logan Tomkins sin-binned for separate incidents and were hammered 8-3 in the first-half penalty count.
Gareth O’Brien kicked Salford ahead with an early penalty, but Sam Williams landed two similar kicks for the hosts and then his pass sent Reece Lyne in for the first try, on 31 minutes.
Two minutes before the break Jacob Miller crossed from Tom Johnstone’s kick, but Wakefield missed a golden chance four minutes into the second half when Craig Huby knocked-on over the line from Liam Finn’s pass.
A converted try would have made it 18-2, but four tries in 12 minutes turned the game on its head as Ben Murdoch-Masila, Kris Welham, Greg Johnson and George Griffin all crossed.
O’Brien converted the first and fourth touchdowns and Salford led 22-12.
Matty Ashurst spilled Williams’ kick over the line with 14 minutes left, but four later Bill Tupou touched down from Kyle Wood’s pass and Williams’ goal cut the gap to four points.
With three minutes left Lyne got over for his second try from Williams’ pass and Williams kept his nerve to land the conversion which made it 24-22.
The game restarted with 42 seconds left, but Salford got the ball back from a short kick-off and Murdock-Masila forced his way over with one second remaining on the clock, but he knocked-on.