Marsh kept his nerve after a record fourth-wicket stand of 161 off 79 balls between David Warner (77) and Glenn Maxwell (75) had rescued the visitors from 32-3 in reply to 204-7.
Skipper Faf du Plessis underpinned the Proteas innings with 79 off 41 balls.
Kagiso Rabada then took 2-25, including the key wicket of number four Warner.
However, it was not enough to prevent the series being levelled, meaning Wednesday's match at Cape Town will be the series decider.
The two teams then fly to India for the World T20.
Australia's Mitchell Marsh scored two off the final ball to secure a dramatic Twenty20 victory over South Africa and level the three-match series.