Steve Lomas' side continued their impressive run of form as Francisco Sandaza's spot-kick winner handed them victory at McDiarmid Park.
Jason Holt's opener for Hearts had earlier been cancelled out by Murray Davidson.
The Perth side now sit four points ahead of Hearts and level with Dundee United in the race to finish fourth.
Lomas made two changes change to the side that beat St Mirren 3-0 last weekend.
Callum Davidson missed out with a hamstring injury and Alan Maybury slotted in at left-back.
Cillian Sheridan also returned after serving a one-match suspension and replaced Chris Millar, who dropped to the bench.
Hearts boss Paulo Sergio opted to shuffle his pack for their third game in the space of a week - making four changes to the side that beat St Mirren in midweek.
Craig Beattie failed a late fitness test, while Ian Black, Jamie Hamill and Rudi Skacel only made the bench.
Sergio handed starts to Arvydas Novikovas, Gary Glen, Scott Robinson and a full debut to Holt.
St Johnstone were unbeaten in four league matches and Hearts were out to extend their unbeaten run to five games.
Marius Zaliukas was forced to clear from his six-yard box as St Johnstone threatened inside 30 seconds.
But Hearts had the first effort when debutant Holt fired a rising volley narrowly over.
Jody Morris' 20-yard half-volley forced a good save from Hearts goalkeeper Jamie MacDonald after seven minutes.
Holt was heavily involved for Hearts but both defences were coping with any attacks and chances were scarce.
Hearts goalkeeper MacDonald survived a scare after 26 minutes when Zaliukas was short with a backpass.
MacDonald beat Fran Sandaza to the ball but took a fresh air kick and the ball crept past the post.
It was a let-off but Sergio's side took advantage as they took the lead after 29 minutes.
Right-back Ryan McGowan raced down the right and fired over the perfect cross for Holt - who finished from eight yards.
Sandaza almost made the most of a mix-up in the Hearts box as St Johnstone chased the equaliser.
It arrived after 35 minutes as Davidson met Dave Mackay's cross and steered a volley beyond MacDonald.
Zaliukas then did well to cut out Lee Croft's cross as Sheridan waited to pounce.
Hearts were forced to make a goalkeeping change at half-time, with Mark Ridgers replacing MacDonald.
His goal came under threat straight away as Sandaza raced clear from the halfway line, but his shot was deflected over.
Sheridan fired a shot wide of target as St Johnstone started to pile on the pressure.
St Johnstone defender Frazer Wright was booked for a late tackle on Holt after 57 minutes.
Hearts midfielder Darren Barr then blazed over the bar from 30 yards.
There was little between the sides but St Johnstone took the lead after 76 minutes through Sandaza's penalty.
The Spaniard fell under a Zaliukas challenge and chipped a cool spot-kick down the middle.
Chris Millar almost added a second for St Johnstone with a looping header.
Andy Driver then wasted a good chance to equalise for Hearts in injury-time.
Glen also smacked the post as St Johnstone hung on.