Zulqarnain Haider and Wahab Riaz were the unlikely heroes with key runs at the death as Pakistan squared their five-match series against South Africa with a nail-biting one-wicket victory in the fourth one-day international in Dubai.
Bowler Riaz (18) and wicketkeeper Haider (19 not out) looked to be fighting a losing cause after key man Abdul Razzaq (33) departed with 31 runs still needed from 23 balls as the Asians hunted down the 275 victory target.
Riaz was dropped by Graeme Smith second ball, but then hit two fours and, together with Haider, mixed aggression with intelligent hitting to edge Pakistan over the line with a ball to spare.
The win completed the earlier good work done by Younus Khan, whose gritty 73 kept the home side in the chase after the Proteas had made 274 for six, thanks largely to Smith (92).
It started indifferently for the Pakistanis after they lost Imran Farhat (two) at the top of the order when he was trapped leg before wicket by Morne Morkel.
But Mohammad Hafeez and Younus brought up an attacking 50 partnership in 47 balls before the stand was eventually broken eight runs later by Dale Steyn.
Hafeez was the man to go, for 42, out lbw to the South Africa paceman, bringing Asad Shafiq to the crease.
Together with Younus they shared another half-century stand, taking their side past the 100 mark in the process.
They were going well together and put on 56, but Wayne Parnell then brilliantly threw down the stumps from mid-on at the non-striker's end to send Asad on his way for 36.
New man Fawad Alam should have followed in the next over, only for Johan Botha to fumble the ball with the batsman way out of his crease.
There was no second chance moments later, though, when he chipped Jacques Kallis straight to David Miller and was out for six.
It left Pakistan on 131 for four and brought the unpredictable Shahid Afridi to the middle.
For a while he played sensibly mixing attack with defence but, after striking four boundaries, he went for one too many and lifted Botha to Parnell for 29.
Younus was still there at the other end and brought up a hard-working fifty from 83 balls - a knock that included no boundaries.
His first four eventually came in the 37th over as Pakistan then reached 200 - still needing 75 from 77 deliveries.
A lazy shot from Younus saw him bowled off an inside edge by Morkel and Abdur Rehman followed for a duck leaving the score at 220 for seven with 7.3 overs to go.
Razzaq kept them in it and along with Haider looked to be taking them to an easy win, but his dismissal - caught behind by AB de Villiers off Morkel - left Pakistan 244 for eight.
Riaz followed suit when was run out attempting a quick single, but Haider saw his side home with Shoaib Akhtar not having to face a ball at the other end.
Earlier, Smith won the toss and batted first, but his side lost the in-form Hashim Amla (10) and Kallis (15) cheaply as they slipped to 62 for two.
The captain and De Villiers began the repair work in a 94-run partnership, before the former, who looked poised for his century, saw his 105-ball knock ended when he was trapped leg before wicket by Hafeez (two for 37).
De Villiers also fell shortly after leaving the Proteas on 191 for four.
JP Duminy (36) took them past 200, but was bowled 26 runs later by Riaz (two for 61), who also cleaned up Miller next ball.
Colin Ingram (27no) and Botha (28no) took full advantage of sloppy fielding towards the end to move their side onto 274 - a total that proved a few runs short.