Although the South Africans had perhaps more of the possession, they were restricted to few clear scoring chances, while the Scots took their opportunities and continue to upset sides above them in the world rankings.
Shepherd’s team stole the lead when Ali Howie’s reverse stick shot eluded the goalkeeper.
The South Africans then put the Scots under severe pressure, but the defence kept their composure and Scotland emerged from the siege with a solo run from the lively Vikki Bunce, who almost provided the second goal.
But the Scots did score again just before the interval when Nikki Lloyd provided Morag McLellan with the chance to poke the ball home.
Although the Scots created a few chances early in the second half through Lloyd and Nikki Kidd, it was Pietie Coetzee, the highest international goalscorer in the women’s game, who pulled one back with a low drag flick.
However, Scotland regained their composure and Kidd put the them 3-1 ahead. Coetzee pulled another back for the South Africans, but the Scots saw out the closing seconds to win.