New signing Paul Dummett had given Saints the lead just before the break thanks to a thumping header but early in the second half Craig Moore equalised.
That looked as if that would be the end of the scoring, despite Saints having a number of chances, but in stoppage time John McGinn snatched victory for Saints with a fine free-kick.
Follow Mirren Mad on Facebook at http://www.facebook.com/mirrenmad
Follow Mirren Mad on Twitter @mirren_mad or http://www.twitter.com/mirren_mad