It handed the visitors their first victory in the league this season as Saints were left struggling without a point after four matches.
Both sides struggled to create too much in a quiet first half, but the signs were ominous as MacDonald looked increasingly dangerous, forcing a smart save from Marian Kello.
But with 10 minutes to go and the teams seemingly settled for a point apiece, the 33-year-old former St Johnstone striker latched on to a long punt to coolly slot home and steal the headlines.
St Mirren introduced Steven Thompson as he continued his return from injury but not even the skipper's influence from the bench could produce a Buddies comeback.
While Dundee moved up to sixth position, the St Mirren fans were left still looking for their first points of the season and only superior goal difference is keeping them above Ross County at the foot of the table.