A dull first half came to life just before the break when George Williams and Scott Tanser hit the woodwork for the visitors, who took the lead in the 65th minute with a David McMillan penalty after Hamilton’s stand-in keeper Ryan Fulton brought down Williams inside the box.
David Wotherspoon fired in a second in the 80th minute but Accies skipper Dougie Imrie reduced the deficit with a header three minutes later.
It was too little, too late to prevent defeat although Partick Thistle’s 1-0 defeat by Motherwell means, with one game remaining, 10th-place Hamilton are three points better off than the Jags with a vastly superior goal difference.
There was little to excite the fans in the opening minutes although there was consternation among the Accies players when midfielder Danny Redmond was booked by referee Kevin Clancy for simulation after going down under a Joe Shaughnessy tackle which looked to be a foul on the edge of the box.
In the 32nd minute Hamilton attacker David Templeton, back from a groin strain, drew a free-kick from St Johnstone midfielder Murray Davidson 25 yards from goal and his curling shot to the near post was brilliantly parried wide by Saints keeper Zander Clark.
Templeton fired the resulting corner out to the other side of the pitch, an error of judgement much more in keeping with the general play.
Then Redmond raced clear of the Perth defence and onto a Templeton pass and, under pressure from the back-tracking Liam Gordon, he sent his left-footed shot past Clark’s left-hand post.
However, it was the Perth side who missed the best chance of the half in the 42nd minute when Williams latched on to Wotherspoon’s deep cross from the left only to cushion his shot from four yards onto the post.
Accies, relieved at the let-off, ran up the other end and Redmond scooped a shot from 14 yards over the bar.
However, St Johnstone came even closer when left-back Tanser rattled keeper Fulton’s upright with a powerful drive from the edge of the box.
Within three minutes of the restart Clark had to fly to his right to save a close-range header from midfielder Darian MacKinnon but the corner was easily defended.
The game became scrappier before Fulton raced from his goal to upend Williams and see Clancy point to the spot, with former Dundalk striker McMillan converting the spot-kick to set Accies nerves jangling.
The Lanarkshire side pushed hard for the leveller but with 10 minutes remaining, Wotherspoon sent a drive past Fulton from substitute Stefan Scougall’s cut-back but Accies soon responded, with Imrie stooping to head in a cross from substitute Mickel Miller.
Hamilton failed to draw themselves level - indeed it looked more likely that Saints would score again - but results elsewhere mean Accies are safe for another season.