In Hearts' final home game of the season and with many saying possible farewells to Tynecastle, Rudi Skacel converted Ryan McGowan's cross after 21 minutes for his 16th goal of the season and Andy Webster netted a second after 58 minutes as the William Hill Scottish Cup finalists ended a three-match winless run.
Saints, who have now gone six games without tasting victory, must now beat Rangers at home on next Sunday's final day of the season and hope Hearts lose at Celtic to prevent the capital club finishing fifth.
However, even if Saints finish sixth, European football could be at McDiarmid Park next season if Hearts win the May 19 Hampden final against Hibernian.
That will be the departing wish for midfielder Ian Black, who was making his final Tynecastle appearance after being told his contract will not be extended, while manager Paulo Sergio's future position is still to be clarified with his deal soon to expire.
Skacel is yet to learn if his second spell at Hearts will be extended and applauded all sides of the ground at the final whistle before joining his team-mates in a lap of honour.
The Czech forward was one of three changes, with Scotland Under-21 goalkeeper Mark Ridgers, who made his first start, and Andrew Driver also coming in.
St Johnstone brought in Marcus Haber and Dave Mackay and were on the defensive early on as Hearts applied pressure.
Jody Morris shot narrowly wide in response, while Liam Craig was booked for a cynical challenge from behind on Driver.
Soon the cup final was on Tynecastle's minds as former Hibs forward Derek Riordan ventured from the visiting substitutes' bench to warm up and received a torrent of abuse. Riordan scored the winner in May 2009 when Hibs last won an Edinburgh derby.
Moments later Hearts were celebrating as McGowan attacked down the right and cut the ball back for Skacel to sidefoot in.
Suso Santana had an effort blocked and Skacel fired over as Hearts sought a second, but the hosts might have found themselves level were it not for timely interventions by Black and the assistant referee.
A Craig set-piece had Hearts in trouble as Steven Anderson's header down was helped towards goal by Murray Davidson, whose effort was blocked on the line by Black before Haber had a strike ruled out for offside.
An unmarked Marius Zaliukas should have scored Hearts' second from a Black corner but headed off target and then Saints came close before the interval.
Ridgers, who was less than convincing at dealing with crosses, palmed away Mackay's centre and responded by saving from Callum Davidson before Cillian Sheridan shot wide.
Morris had another long-range strike which Ridgers claimed at the second attempt while Hearts were temporarily reduced to 10 men, with Darren Barr undergoing treatment before going off for Scott Robinson.
Hearts doubled their lead when Saints failed to deal with an inswinging free-kick from Danny Grainger and the ball dropped for Webster to prod in from close range.
Zaliukas headed wide soon after as set-pieces continued to trouble Saints, who replaced Chris Millar with Riordan with 29 minutes to go.
Riordan, jeered every time he touched the ball, was unable to inspire a comeback and fired over after beating the offside trap as Saints fell two points behind Hearts.