The Proteas had won the opener but half-centuries from Mohammad Hafeez and Umar Akmal helped Pakistan set a testing target of 177.
The bowlers did not prove as impressive as South Africa got off to a good start in reply but three quick wickets from Shahid Afridi halted momentum and the tourists held on.
The hosts responded to Pakistan's onslaught confidently with Hashim Amla and Quinton de Kock rotating the strike and despatching anything short or wide to the boundary.
A couple of good balls also got the treatment with Amla getting the Proteas to 49 without loss with a gorgeous punch to finish the fifth over.
The next duly brought up the fifty partnership off 33 balls with De Kock clipping a ball from Saeed Ajmal off his pads for a single
South Africa looked to be making serene progress but Afridi was the man to break the openers up with the first ball of his spell.
De Kock attempted to slog-sweep the veteran to the boundary but Nasir Jamshed was alert to complete a smart take at deep fine leg and send the wicketkeeper back for 26.
And Afridi had his second wicket soon after when skipper Faf Du Plessis was caught by a diving Hafeez who did well to hold on.
That brought AB de Villers to the crease and he hit two fours off Hafeez but was soon to become Afridi's third victim in a many overs as he dragged onto his stumps for 13.
It looked increasingly like the home side's hopes could rest on Amla but he was next to go for 48, slogging Ajmal to Bilawal Bhatti at deep square leg.
David Miller and JP Duminy had a good late slog with 19 off the penultimate over presenting a reachable target of 17 off the last six balls but Pakistan held out.
Earlier, the tourists had got off to a sluggish start after winning the toss and it was not until Hafeez and Akmal came to the crease that they picked up their run rate.
The captain strode out after Ahmed Shehzad was dismissed for nine with the first ball of the fifth over as he swung his bat at a wide one from Wayne Parnell and top-edged to Amla in the slips.
Fellow-opener Jamshed was not far behind when he came down the pitch but missed Aaron Phangiso's flighted delivery and De Kock claimed a simple stumping.
The rate had been upped by Hafeez and Akmal and the former hammered three huge sixes in a 12th over from Phangiso which yielded 21 runs.
Hafeez moved to his fifty in the following over as he swatted a poor full toss from Duminy to the boundary for four.
He had been making most of the running but in the 15th over Akmal got in on the act as he clattered two almighty sixes, one which flew over the head of the despairing fielder at point.
That over produced 22 runs and the next yielded 14 with Akmal powering another colossal maximum over the straight boundary.
The following ball was hit for four to bring up the 100 partnership off just 51 balls and Akmal then moved to his fifty with a single.
The partnership came to an end just three balls later when Hafeez hit a Dale Steyn delivery to De Villers but he had done his part with his 63 coming off 41 balls.
That brought Afridi to the crease and although he did not hit his usual stride with the bat, he provided a good foil for Akmal who eventually fell for 64 as he skied Steyn to Duminy with two balls remaining.