Salford led 24-8 with seven minutes left, but three unanswered tries - from James Roby, Regan Grace and Jonny Lomax - gave the home side the momentum.
Smith then slotted over from 40 yards to complete the win.
Defeat for Salford means they slip to third and are eight points behind leaders Castleford, who beat Leeds.
Hull FC climb to second, courtesy of their win over Wakefield, while St Helens stay sixth.
Smith had put Saints ahead with the first try of the match before Niall Evalds capitalised on a defensive error to level the scores on the brink of half-time.
Greg Johnson and Robert Lui crossed for Salford shortly after the break before Evalds added another to put the visitors in a commanding position.
But the Red Devils then tired in the late stages to lose a third successive league game and be denied their first win at St Helens for 37 years.
St Helens coach Justin Holbrook:
"It was fantastic to see that sort of finish. I'm just as excited as the players. I know it's easy to say because we won, but I was always confident that we had a chance.
"We were unlucky not to have led at half-time and in the second it was all Salford. They completed every set and didn't give us a chance.
"It was very gutsy from us. It is great for the players to have that belief to finish like that."
Salford coach Ian Watson:
"It was a tough lesson and a tough way to learn a lesson. We didn't play particularly well in the first half but we rectified that in the second.
"We started to play with resilience in defence, but in the last 10 minutes it was like we'd already won the game. If you do that against any good team you're going to get bit.
"We need to take that as a lesson and learn it pretty quickly because the further you get down the track, there are going to be big games where we need that arm-wrestle mentality."
St Helens: Lomax, Swift, Makinson, Percival, Grace, Fages, Smith, Walmsley, Roby, Amor, Taia, Wilkin, Knowles.
Replacements: McCarthy-Scarsbrook, Douglas, Thompson, Lee.
Salford: Evalds, Bibby, Welham, Sa'u, Johnson, Lui, T. Carney, Tasi, Tomkins, Kopczak, Murdoch-Masila, Lannon, Flanagan.
Replacements: Hauraki, Jones, Hasson, Brinning.
Referee: Scott Mikalauskas (RFL)
Matty Smith scored a drop goal in the final seconds as St Helens completed a stunning comeback to beat Salford Red Devils.