The Paisley outfit picked up just their fourth league win of the campaign as they secured their first league victory on the road this season.
Saints had hit the woodwork three times before MacPherson fired them into a 52nd-minute lead with a well struck shot from the edge of the box.
The visitors came close to opening the scoring in the fifth minute when Jonathan Obika flicked the ball into the path of Ilkay Durmus and his crisp angled drive was pushed onto the crossbar by Luke Southwood.
Accies began to pose more of a threat as the first half wore on and when Mickel Miller whipped in a cross only the intervention of Kyle Magennis at the far post prevented Steve Davies from having a sight of goal.
Hamilton had a big shout for a penalty when Marios Ogkmpoe tumbled inside the penalty area under pressure from Calum Waters as he was about to latch onto Lewis Smith's cross but referee Don Robertson waved away their appeals.
St Mirren went close to breaking the deadlock in the 34th minute when Junior Morias laid a long punt forward from goalkeeper Vaclav Hladky into the path of Obika and his snapshot from the edge of the box went just wide.
St Mirren piled on the pressure at the start of the second half and just 19 seconds into that Morais outmuscled Sam Stubbs as they competed for a long ball and prodded a shot goalwsard but it struck the post.
Saints hit the woodwork for a third time in the game when MacPherson whipped in a free-kick that Southwood got a fingertip to to push it onto the crossbar.
But the deadlock was finally broken in the 52nd minute as St Mirren's pressure finally told.
Durmus delivered a cross from the left wing that was met by Hamilton defender Brian Easton but he failed to get enough distance on his clearing header as it fell to MacPherson on the edge of the penalty box and he lashed in a low shot that beat Southwood.
Durmus went close to a second but his goalbound effort was blocked by Aaron McGowan and then MacPherson curled a free-kick just wide.
Southwood kept Hamilton in the game as he pulled off a fine save to deny substitute Cooke.
Hamilton were reduced to 10 men with 13 minutes remaining when Gogic was shown a straight red for denying a clear goalscoring opportunity when he bundled over Cooke as the striker bore down on goal.