Graham Carey's bolt from the blue booked St Johnstone's place in the Scottish Cup semi-final.
The 35-year-old produced a moment of magic against Livingston to seal a trip to Hampden for the Scottish Premiership strugglers.
In a second half bereft of clear-cut chances, and largely devoid of any real quality in either final third, Carey's stunning 30-yard strike was well worthy of winning the final tie of the quarter-final.
Such was the nature of the winner, it left team-mates stunned and manager Simo Valakari with his hands on his head amongst jubilant celebrations.
St Johnstone will face Celtic at Hampden next month with Hearts and Aberdeen going head-to-head in the other semi-final contest.
St Johnstone had the first sight of goal just two minutes into the contest when Jason Holt ought to have opened the scoring. Stephen Duke-McKenna raced clear down the line and whipped into the box where Holt was unmarked but he was not set for a first-time finish as he harmlessly flicked the ball into the arms of Jerome Prior.
Three minutes later and Livingston threatened an opening goal of their own. Robbie Muirhead sent an inviting cross to the backpost for Andrew Shinnie to nod across goal but Andy Fisher did well to claw clear.
The Livingston midfielder had another major opportunity with 13 minutes played as Macaulay Tait snatched the ball and played through Shinnie but this time his low drive trundled wide of the margin.
By this point, Livingston were controlling the majority of the ball and seriously pushing to take a lead against their Scottish Premiership opponents.
But for Fisher, the hosts would have been ahead in the 16th minute. A long throw from Muirhead picked out Danny Wilson who looked to have scored with an excellent header but Fisher again played spoiler as he hooked it off the line with an outstretched arm.
St Johnstone may well have been fortunate to still be level, but Adama Sidibeh should have fired them ahead moments later if not for a careless offside. The rapid striker coolly slotted home from a Sam Curtis ball, but he needlessly ran beyond his marker with the offside flag ruling out an opener.
Replays showed claims for a penalty for Livingston before the St Johnstone scare as Shinnie fell in the box clutching his face after a coming-together with Daniels Balodis. The Perth stopper looked to hold off Shinnie as his hand accidentally connected with Shinnie's face but play was waved on.
The hosts weren't spooked by the lucky escape as they quickly returned to a dominant role in the first 45 minutes with Muirhead again causing problems. A brilliant piece of skill from Tete Yengi in the box saw his backheel to Muirhead but the striker sliced wide with the goal at his mercy.
One minute later, with 27 on the clock, Scott Pittman tried his luck but saw a curling effort land on the roof of the net.
A lacklustre end to the first half bled into a chanceless opening period after the restart with Stephen Kelly's wild sky-high strike after an hour the first genuine effort on goal.
Balodis summed up proceedings in the 69th minute as he escaped his marker in the box but could only divert his effort away from goal.
At this point, it appeared it would take something sensational to break the deadlock in West Lothian, and Carey delivered with 73 minutes played.
The substitute, only on the park for three minutes, sent a thunderous effort into the top corner from no less than 30 yards. A Drey Wright cross was cleared to Carey who, buoyed by shouts from the travelling support, shaped up to strike from improbable range to leave both goalkeeper Prior, his own team-mates and manager Valakari stunned as the shot crashed in off the underside of the bar.
St Johnstone could have put the match out of reach for Livingston ten minutes from the end as Wright picked out Sidibeh in the box but the striker's diving header was comfortably held by Prior.
Wright, himself, then passed up a glorious chance as he blazed over the crossbar. Holt had stolen a march into the right hand side of the box and cut back for Wright but he completely miscued as he conspired to miss the gilt-edged sight of goal.
Makenzie Kirk went close to making sure of victory in stoppage time as he launched a volley at goal but Prior was equal to the effort as he beat it clear of danger.
Livingston boss Davie Martindale had rolled the dice with a triple change five minutes from the end with Reece McAlear, Meshack Ubochioma and Matthew Clarke thrown on in hope of a late leveller.
There was nothing doing, though, with the hosts failing to trouble Fisher even on one occasion in the second half in a major opportunity missed for the Scottish Championship promotion hopefuls.