The Tigers trailed 12-4 at the break after tries from Mark Percival and Louie McCarthy-Scarsbrook.
However, Cas, for whom debutant Kieran Gill scored in the first half, reduced the deficit through Mike McMeeken.
Tom Holmes crossed to secure a seventh straight victory for Daryl Powell's side.
Second-placed Salford Red Devils were beaten 34-24 at home by Wakefield.
Powell, whose side played three games in nine days last week, made several changes, following the lead of other Super League coaches this weekend as he described their schedule as "a nonsense" and "appalling".
In contrast, Saints, who went into the game after a nine-day rest, will be disappointed they did not do more with the pressure they had at the start of the second half when leading by eight points.
Cas return to action with a home game against struggling Warrington next Sunday, while Saints host improving Widnes on Friday.
Castleford coach Daryl Powell:
"It's one of the biggest wins I've been involved in.
"For a team that had been played about with to roll into a game against opposition that had a significant rest period on us and a full-strength team and come out with that kind of performance was awesome.
"We had to dig in right at the end and the amount of scrambled tackles to keep them out shows the character we've got.
"What we've become as a club is we've got genuine depth and belief that we've got something special here."
St Helens coach Justin Holbrook:
"We knew it was going to be a tough game and it would have been great to win. To fall just short is very disappointing.
"Castleford obviously weren't at full strength but they haven't lost here for a reason. They're a very good footy side and they showed that again today.
"But it was a missed opportunity. They had the luxury to rest a few today because of where they are sitting in the table and they earned that.
"For us to fall just short, it's really costly for where we're sitting in the table.
"It was disappointing we didn't get the win but I'm really happy with the squad and we came really close today. It's important we just move on to next week."
Castleford: Eden; Gill, Webster, Monaghan, Minikin; Roberts, T Holmes; Lynch, McShane, Massey, Foster, Larroyer, Sene-Lefao.
Replacements: McMeeken, Moors, Hitchcox, Trueman.
St Helens: Makinson; Swift, Morgan, Percival, Grace; Lomax, Smith; Walmsley, Roby, Amor, Taia, Wilkin, Knowles.
Replacements: Lee, McCarthy-Scarsbrook, Douglas, Thompson.
Referee: Chris Campbell (RFL).
Castleford Tigers came from behind to beat St Helens at The Jungle and extend their lead at the top of Super League to four points.