Spartans made home advantage pay in their Challenge Cup preliminary round first leg with Threave Rovers.
Robbie Ross tapped home a Jack Beesley cross to put the home side in front before doubling his and his side's tally with a deft flick.
A Shaun Milligan tap-in gave Threave an lifeline and Scott Wilby converted a penalty to level the tie.
However, a late Kevin Motion spot-kick and a last-minute Chris Anderson strike earned Spartans a dramatic win.
The sides play the second leg on 20 July, with the winners to face holders Queen of the South in the first round.