George Oakley's first goals for the club gave Brian Rice a first win as Hamilton Academical head coach and moved his side three points clear of the Scottish Premiership's bottom two.
Oakley twice converted at the near post from Mickel Miller and Tony Andreu deliveries from the left.
Liam Craig briefly brought St Johnstone level from close range.
The Perth side remain sixth after a fourth league defeat in a row but are just four points clear of Motherwell.
Accies, who avoided an eighth straight defeat by St Johnstone, extend their advantage over second-bottom Dundee to three points and are now six clear of St Mirren.
For three quarters of this game, St Johnstone had edged matters and indeed created the more clear cut openings.
Craig was denied early by Hamilton goalkeeper Gary Woods and wide men Matty Kennedy and Michael O'Halloran threatened in the second half.
Rice took action to change the course of the match, introducing Miller for Dougie Imrie and Andreu for Steven Boyd. And Miller cut back from near the bye-line to set up Oakley's first.
Craig then passed into an empty net at the other end after Tony Watt's replacement, Chris Kane, had turned his man and taken Woods out of play with his cross.
But Hamilton responded almost instantly, Andreu lifting the ball in for Oakley to apply another poacher's finish.
St Johnstone could not find their rhythm again and Hamilton saw out their first win since 1 December.
Rice's men get the weekend off, with Accies having been knocked out of the Scottish Cup last month.
St Johnstone, on the other hand, face a third game in 10 days against Celtic, Sunday's cup tie following two league defeats in recent days.
BBC Scotland's Jane Lewis at the Hope Stadium
Either side could have won this terrific match, but it was Hamilton who took their opportunities when they fell. And what a big win for Rice. Two games as head coach and four league points.
His attacking intent was clear from the off and his January signings played a part in that. Oakley and Steve Davies look to have settled in well, while Steven Boyd seems to have found a new lease of life. His energy was impressive.
Hamilton are still likely to be embroiled in things at the bottom of the table, but this win will up the confidence. But will the opposite be true for St Johnstone? It's now four defeats on the trot but manager Tommy Wright insists the losses will not affect the players in a negative way.
'A day I'll never forget' - reaction
Hamilton head coach Brian Rice: "I'm absolutely delighted. It's my first win as a head coach. It's a day I'll never forget.
"Everybody to a man fought their corner, won their headers, won their tackles and when they made a mistake, they recovered and that's all I ask of them. It's massive for confidence right through the club, right through the town."
St Johnstone manager Tommy Wright: "Poor result and poor goals we've given away, which have cost us. We should deal with both goals a lot better.
"I probably thought we did enough for a draw but when you make mistakes like we did, it's hard to get any points. They'll be strong enough to bounce back. We've had worse runs than this."