Matej Poplatnik netted an extra-time winner to send Livingston into the fourth round of the Scottish Cup at Raith Rovers' expense.
The Slovenian climbed off the bench to stroke Nicky Devlin's cut back into the net in the 109th minute.
Championship side Raith had started brightly and went ahead in the 13th minute through Lewis Vaughan's stunning free kick.
But the Lions levelled in the 70th minute through Jack Fitzwater.
The top-flight outfit were first to threaten after seven minutes when Devlin had a header from Craig Sibbald's corner headed off the line by Dylan Tait.
However, Rovers broke the deadlock with an exquisite free-kick from Vaughan.
The striker curled an effort over the wall and past Robby McCrorie at the goalkeeper's near post.
Raith kept coming as the hosts struggled to get a foothold in the game.
Reghan Tumilty had a near post drive repelled by McCrorie from close range before Regan Hendry then shot straight at the on loan Rangers keeper from 18 yards.
A quick-free kick then caught out Raith in the 21st minute when Sibbald fed Jay Emmanuel-Thomas inside the area but Jamie MacDonald got down at his front post to make the save.
The last chance of the opening period fell to Raith when Tumilty had a half-volley pushed behind by the outstretched McCrorie.
Livingston improved after the break and were denied by another goalline clearance from Tait after Jackson Longridge's shot was deflected towards goal.
But the hosts levelled through Fitzwater, the defender turning Jon Guthrie's knock-down into the net from close range from Josh Mullin's corner.
Extra-time was a tight affair, the first chance of note coming in the second period when Raith keeper MacDonald made a comfortable save from Devlin's looping header.
But Devlin then turned provider in the 109th minute. The full back raced into the box and his square ball was placed into the gaping net by sub Poplatnik at the back post.