Christian Nade gave the hosts the lead with a thunderous strike in an otherwise drab first period.
St Johnstone levelled on the hour from a fine Collin Samuel header before Hearts' Jose Goncalves was sent off for a dangerous challenge on Liam Craig.
Saints exploited their advantage and sealed the points with minutes to go.
The win lifts St Johnstone above Hearts into eighth place, but it was the hosts who looked more threatening going forward early on with Nade involved in good build-up play and David Obua supporting well on the left.
It was they who combined to set up Ian Black with a chance which he swept past Graeme Smith's post.
But at times the Hearts looked hesitant in the centre of defence and their failure to deal with a high ball on 12 minutes allowed St Johnstone's Felipe Morais to fire a crisp shot at Janos Balogh.
On the half-hour mark Nade teed up Gary Glen from outside the box, but the Hearts forward's attempted curling effort was weak and straight into the goalkeeper's arms.
Neither goalkeeper had had a serious save to make in a fairly uneventful first half, but Smith could have done nothing to prevent Nade's stunning opener. The Frenchman spun and dragged the ball away from a defender before unleashing a wonderful shot from thirty yards which flew inside the far post.
The goal - Hearts' first in three games - lifted the hosts, who then went close from Obua and Jason Thomson. But with a simple high ball down the middle Morais could have equalised if Balogh had not been quick off his line to block the Portuguese player's effort.
St Johnstone upped their game after break but, like the first half, there was little action of note until the Perth side equalised on the hour.
Morais twisted and turned on the left wing before swinging over a teasing cross which Samuel rose well to head past Balogh. Samuel watched two further efforts go wide, before Jody Morris had a glorious opportunity to put Saints ahead. But Balogh again came to Hearts' rescue with a point-blank block from the Londoner.
The home side were forced to play the last 10 minutes with 10 men after Goncalves was sent off for a dangerous challenge. The Portuguese defender's boot was high but did not make contact with his opponent. As St Johnstone pushed to take advantage of their depleted opponents, Craig had a back post shot deflected over from six yards.
And with four minutes remaining Johansson, just on as a substitute, arrived at the back post to divert in Craig's header, and seal the three points for St Johnstone. -