Dumbarton will take a one-goal advantage into the second leg of the League One play-off final after edging out Spartans.
Tony Wallace and Finlay Gray struck in the first half to put Dumbarton in command before Ayrton Sonkur halved the deficit before Friday’s return game in Edinburgh.
Wallace prodded home from close range in the 21st minute after Gallagher Lennon’s effort came back off the crossbar.
Gray doubled Dumbarton’s lead eight minutes later following Michael Ruth’s burst down the left.
However Sonkur finished off from 12 yards when he looped the ball over the outstretched arms of Jay Hogarth in the Dumbarton goal.
James Craigen had an opportunity to equalise when he was played clean through on goal but he blasted the ball off the top of the crossbar.