Patrick Walker scored with almost the last kick of the game to put Dumbarton in to the Ramsdens Cup second round.
Bryan Prunty prodded Sons ahead from Mark Gilhaney's cross in 52 minutes and Gilhaney scored from the spot after Iain Chisholm fouled Kieran Brannan.
Alistair Love pulled one back and Dumbarton had James Lyden sent off for a foul on the visitors' goalscorer.
Kevin Turner's tap-in levelled the score but in the second minute of injury-time Walker fired in the winner.
: Grindlay, Lyden, Nugent (Wallace 67), Lithgow, Nicoll, Gilhaney, Agnew, McBride (Ramage 78), Brannan (Metcalf 83), Walker, Prunty. Subs Not Used: Ewings, McNiff.
: Lyden (67).
: Prunty 54, Gilhaney 61 pen, Walker 90.
: Antell, Chisholm, Frances, Cane, Dingwall, Love, Hunter (Sheerin 87), Jackson, Stirling, Turner (Team 87), Lurinsky (Savage 74). Subs Not Used: Sorley, Beveridge.
: Frances, Chisholm.
: Love 66, Turner 70.
: Paul Robertson