The visitors gave a good account of themselves and Ethan Erhahon's wonder-strike early in the second half gave them a deserved lead.
But it only served to spark life into a below-par home side though, and the Dons levelled with 20 minutes remaining through Marley Watkins.
A share of the spoils looked likely until Ferguson popped up to hit a low shot that seemed mis-hit into the bottom-left corner to secure his side all three points.
Saints' Jak Alnwick was the busier of the keepers in the early stages, his early stop from Jonny Hayes perhaps a little less than convincing and allowing Niall McGinn the chance to follow up, only for Marcus Fraser to block.
Alnwick was involved again a few minutes later as he raced off his line to head a long ball clear but left team-mate Conor McCarthy requiring treatment after a heavy collision between the pair.
And the goalkeeper was forced into another save, this time low to his right, after an advantage allowed by referee Gavin Duncan allowed Ferguson a sight of goal from the edge of the area.
But as the first half wore on, the visitors came more into the game and it took a timely intervention from Tommie Hoban to deny Jon Obika as the striker stole in behind Ash Taylor from a Lee Erwin flick.
And a MacPherson free-kick, headed by Obika, fell to Erwin on the angle eight minutes before the break, but his angled effort was held by Joe Lewis at the second attempt.
The visitors' endeavour was rewarded in the early stages of the second half when the unlikely figure of Erhahon struck a sweet 25-yard drive that arrowed past Lewis and into the top-left corner.
Watkins had a sighter after 69 minutes, sending a low shot straight down the throat of Alnwick, but two minutes later he found the back of the net, firing into the bottom-left corner after a move conducted by Ryan Hedges.
Bruce Anderson came off the bench and passed up a decent opportunity before Ferguson struck a mis-hit shot from the edge of the box that caught out Alnwick and trickled into the bottom left corner.