45 overs Pakistan 262 (Shehzad 102, Steyn 6-39) beat South Africa 261 for 6 (Amla 98, De Villiers 74, Junaid 3-42) by one run
Scorecard and ball-by-ball details
Junaid Khan defended nine runs off the final over to ensure Pakistan secured a first ever bilateral ODI series win over South Africa. In a rain-reduced affair, which was curtailed to 45-overs a side, Ahmed Shehzad's century provided Pakistan with a challenging total. South Africa, playing in their 500th ODI, looked well set to chase it down courtesy Hashim Amla and AB de Villiers, but the pressure got the better of them once again and they fell one run short.
A 110-run fourth-wicket partnership between Amla, whose 98 was crafted from patience, and de Villiers, who provided a dazzling display of innovation with 74, brought South Africa's required run-rate down to less than a run a ball. With the equation in their favour, it seemed South Africa would better their poor record batting second - they have not won a match chasing since March this year - in the decider of the three-match series against Pakistan. But Amla and JP Duminy were dismissed in the space of three balls, new batsmen were at the crease, Saeed Ajmal turned the screws in the penultimate over, Junaid produced a full bouquet of yorkers, and Pakistan claimed a historic victory.
There were times when it seemed they would not get there. After Junaid did the early damage and got rid of Graeme Smith, South Africa laid a foundation through Amla and Quinton de Kock, who provided a mix of fortitude and flair to keep South Africa on track. Amla was happy to let de Kock execute the meaty swings while he dropped anchor.
Shahid Afridi's golden-arm broke through their partnership when de Kock tried to clip the ball over midwicket and found silly mid-on instead. Afridi also claimed the big scalp of Jacques Kallis but by then Amla had reached fifty and South Africa were set.
With de Villiers joining him, South Africa had their two top ODI batsmen in operation and they seemed certain to take them over the line. De Villiers attacked from the get-go, driving Bilawal Bhatti through extra cover, and then accelerated off Mohammad Hafeez, Ajmal and Anwar Ali.
He danced down the track, he cut, he brought up his half-century with a fierce pull, he swept and got down on on knee to impersonate Brendon McCullum's paddle. And then he perished trying to repeat it. Afridi took the catch at deep square leg.
Still, South Africa seemed in control. They required 36 runs off 38 balls and Amla was still there. He was soon in the nineties. He was the man who could withstand the Ajmal stranglehold, but he showed he was human too. He tried to reach the milestone with a six over square leg but top-edged to Hafeez and that was the start of South Africa's end. Ajmal's job was done, Junaid followed up well and South Africa's soft underbelly was exposed again.
The questions surrounding their batting may drown out any thoughts of their bowling, which stands in line for much praise and some concern. Dale Steyn recorded career-best figures of 6 for 39 and bowled the poisoned-tip any spearhead should.
Steyn claimed the early wickets of Nasir Jamshed and Mohammad Hafeez - who he has now accounted for him 15 times in 23 matches across formats - and came back to puncture Pakistan at the end. What he lacked was support from an attack that had been changed to include the fit-again Lonwabo Tsotsobe and Ryan McLaren. The seamers struggled to fine their lines while there was little on offer for the slower bowlers, making them fairly ineffective.
Once Steyn had had his way with the top order, Pakistan rebuilt through Sohaib Maqsood and Shehzad. They rotated strike well and did not force boundaries, instead waiting for Jacques Kallis to overpitch, JP Duminy to offer flight or Ryan McLaren to allow them to get under the length.
Maqsood threw it away, trying to launch McLaren over extra cover and finding Amla, but Shehzad plugged on. He crossed 1000 ODI runs, survived while Misbah-ul-Haq was caught down the leg side off Imran Tahir and, after 108 balls at the crease brought up his third ODI century. He looked set for many more but was run-out when Umar Akmal was ball-watching when he called for a single.
Akmal made up for that mistake by providing the lower-order flourish which took Pakistan to a competitive total. He was the anchor of the 82 runs they scored in the last 10 overs. He took on McLaren and Steyn with extravagant shots and even though he was Steyn's fifth wicket, he had done enough to roll out the canvas on which the bowlers could paint a memorable win.
Firdose Moonda is ESPNcricinfo's South Africa correspondent