Excellent bowling in the morning session was backed up with steady batting under the hot sun as they chased down a victory target of 182.
South Africa now lead the three-match series 2-0 with one match remaining in Centurion starting on Feb. 22.
Hashim Amla anchored their chase with an enterprising 58 from 96 balls that drained the belief from the Pakistan bowlers.
The tourists picked up some late wickets to allow spinner Saeed Ajmal to record match figures of 10 for 147, but by then the game was lost.
Starting their innings 30 minutes after lunch having bowled Pakistan out for 169 in their second innings, the home side lost the early wicket of Alviro Petersen lbw to Umar Gul for one.
Graeme Smith (29) then became Ajmal's first victim of the innings when he was also trapped in front going on the sweep, the second time in the test he has been out in that fashion.
Jacques Kallis hit a brisk 21 before being dismissed lbw by Ajmal.
Amla was magnificent as he steered the ball all round the ground, but was bowled as he had an uncharacteristic wild swing at an Ajmal delivery, bringing an end to his fine knock.
AB de Villiers (36) also played a reckless flashing cut that was caught by wicketkeeper Sarfraz Ahmed off Tanvir Ahmed to give the bowler his only wicket of the test.
Faf du Plessis (15) was lbw to Ajmal with two runs needed, but Dean Elgar (11 not out) smashed the winning runs.
Perhaps fittingly, he was at the crease at the time with man of the match Robin Peterson (1 not out), who had changed the course of the match with his 84 on Saturday and fine bowling on the fourth morning.
The victory was set up by South Africa taking seven Pakistan wickets for the addition of 69 runs.
The tourists resumed on 100 for three, but it was not long before the hosts had their first breakthrough.
Misbah-ul-Haq attempted a poorly executed sweep off Peterson and sent a top-edge flying to Graeme Smith at leg slip, the batsman departing for a patient 44.
Asad Shafiq (19) was next to go, unlucky to see the ball bounce onto the stumps after it looped up following his back-foot defensive shot off Vernon Philander.
Then came a collapse that rocked Pakistan as they lost three wickets in as many balls.
Sarfraz Ahmed (five) left a Peterson delivery that turned out of the leg-side rough and cannoned into his stumps.
It was the last ball of the spinner's over, with Philander taking up the attack from the other end and getting wickets with his first two balls.
Ali had reached his 14th test half-century when he edged to wicketkeeper AB de Villiers for 65, and Gul lasted one delivery as he was brilliantly caught by a diving Petersen at third slip.
Ajmal (four) was bowled around his legs by Peterson and Mohammad Irfan (two) was the last wicket down as he fended a Dale Steyn bouncer to Petersen in the slips.