South Africa, sixth in the International Cricket Council Test rankings, beat top-ranked India by seven wickets to clinch the three-match series 2-1.
It was a tense chase, with South Africa having to work for almost every run after being set to make 212 on a pitch which gave assistance to the fast bowlers.
Petersen, on 59, survived a straightforward chance to Cheteshwar Pujara at first slip off Jasprit Bumrah in the seventh over of the day.
Petersen went on to add 23 more valuable runs as he and Rassie van der Dussen (41 not out) put on 54 runs after resuming at the overnight 101 for two.
Van der Dussen and Temba Bavuma (32 not out) took South Africa to victory 35 minutes after lunch with an unbeaten stand of 57.
South Africa looked up against it after India stormed to victory in the first Test before the hosts levelled in Johannesburg to go on for a memorable series success.