St Johnstone spurned the chance to move out of the Scottish Premiership relegation play-off spot after being shocked by Livingston.
Craig Levein's side led after eight minutes through Adama Sidibeh and enjoyed an intense spell of early pressure.
However, despite dominating, St Johnstone found themselves level when Livingston netted with 20 minutes left, Cristian Montano coolly finishing from a Stephen Kelly corner.
Then, in a crushing blow to the visitors, Andrew Shinnie netted deep into stoppage-time to win it for the relegated side.
St Johnstone remain two points behind 10th-place Ross County with two games of the league season remaining.
Showing their attacking threat right from the first whistle, St Johnstone nearly found the net inside 60 seconds when Nicky Clark fired over.
Shamal George was twice called into action early on as his side struggled. Stevie May’s glancing header and Sidibeh’s point-blank diving header were both excellently kept out by the Livingston number one.
George could do little with the opener, however, after being wrong-footed by a scuffed shot by May that found Sidibeh at the back post.
The away side attempted 10 shots in a domineering opening 20 minutes, but struggled to keep that intensity up for the remainder of the first half.
As Livingston began to grow into the game, Perth goalkeeper Dimitar Mitov was tested three times before the interval - a sign of what was to come.
The home side kept battling and levelled in the 70th minute. Montano was unmarked at the back post and, without any contest, tidily fired in the equaliser.
A flurry of changes set up a chaotic end to the game, which culminated in Livingston finding the winner five minutes into stoppage-time - not long after Clark missed a gilt-edged chance to win the game for the visitors.
Steven Bradley picked out fellow substitute Shinnie with a cross, allowing him to fire past Mitov to seal all three points for the Championship-bound club.
Player of the match - Shamal George (Livingston)
Saints fall off as Livi fight to the end - analysis
Livingston boss David Martindale stated his side would fight for “sporting integrity” pre-match. For a short while, that seemed like a fanciful claim.
The home side were dismantled in the opening 20 minutes, with St Johnstone looking as if they would run rampant as Clark, May and Sidibeh all threatened.
After positive changes by Martindale and some great stops from George, Livi threw bodies forward until the full-time whistle to pick up a morale-boosting three points.
You will do well to find a side who have ever rued as many chances in a single game as St Johnstone here.
The Perth side ran riot early on but failed to convert their chances, with Sidibeh’s opener essentially an open goal that could not be missed.
Starting strong but falling off rapidly was St Johnstone’s downfall.
Cammy MacPherson impressed throughout on his long-awaited return but few others in the team sustained their early levels of performance for the full 90.
St Johnstone’s inability to finish good chances is the primary reason they failed to rise above Ross County. But not the only one.
Defensive fragility under pressure and an overreliance on Dimitar Mitov’s shot-stopping could also drag them down to the second tier alongside Livingston.
What the managers said
Livingston manager David Martindale: "We find ourselves 1-0 down and I thought from around 20-25 minutes, we were on the ascendancy. Credit to the players, you can see they are still trying to win games of football.
"I’d love to see Cristian [Montano] with 38 games under his belt. He’s been hampered with injuries since he came here but he seems to chip in with big goals."
St Johnstone manager Craig Levein: "It’s a strange game isn’t it? It’s probably the best we’ve played since I have come into the club.
"We created loads of chances and we come off with zero points, which is baffling to say the least. We made a couple of mistakes defensively and you can’t afford to miss chances and to make mistakes in your own box."
What's next?
Livingston travel to Aberdeen and St Johnstone host Ross County in a season-defining game, both on Wednesday (19:45 BST).