Adama Sidibeh's late goal earned St Johnstone a battling victory against second-tier Hamilton Academical and a place in the Scottish Cup quarter-finals.
With less than four minutes left, Graham Carey tried his luck from 30 yards out and fellow substitute Sidibeh reacted quickly to guide a header into the opposite corner, leaving Hamilton goalkeeper Dean Lyness stranded.
The Championship side had lost their previous three matches, but started the game brightly with Nikolay Todorov twice coming close.
Saints should have led before half-time, but Makenzie Kirk and debutant midfielder Jonathan Svedberg both headed straight at Lyness.
After the break, Accies substitute Oli Shaw could not beat home goalkeeper Andy Fisher after being played clean through, with murmurs of discontent starting to come from the stands.
However, the home side gradually took control as the half progressed and only some last-ditch Hamilton defending kept Kirk out.
Then, just as extra-time looked inevitable, Sidibeh delivered the game's decisive moment, heading home to continue the hosts' recent resurgence - they have now won four games on the spin.