A century by Babar Azam set up a three-wicket, last-ball win for Pakistan in the first one-day international against South Africa at SuperSport Park in Centurion on Friday.
The Pakistan captain hit a stroke-filled 103 off 104 balls but his dismissal started a collapse in which fast bowler Anrich Nortje took four wickets in four overs.
Rassie van der Dussen hit 123 not out, his maiden international century.
But South Africa's total of 273 for six did not seem enough as Babar and Imam-ul-Haq (70) put on 177 for Pakistan's second wicket, taking them to within 88 runs of victory with 18.2 overs left before Babar was caught behind off Nortje.
Four wickets fell for 17 runs.
Mohammad Rizwan and Shadab Khan steadied the innings in a partnership of 53 but both were dismissed in the closing overs before Faheem Ashraf hit the winning run off the final ball.
Pakistan captain Babar Azam earlier said the presence of some moisture in the pitch influenced his decision to bowl first. Pakistan gave a first cap to batsman Danish Aziz.
Temba Bavuma, captaining South Africa for the first time, said the hosts would seek to post a total of about 280.
“There might be something in the wicket for the bowlers but on this ground we can score quite a lot at the end if there are wickets in hand.”
Both teams opted for pace-based bowling attacks, with three specialist fast bowlers, one spinner and a seam-bowling all-rounder.
The three-match series is part of the International Cricket Council's World Cup Super League.
Teams:
South Africa: Temba Bavuma (capt), Quinton de Kock (wkt), Aiden Markram, Rassie van der Dussen, Heinrich Klaasen, David Miller, Andile Phehlukwayo, Kagiso Rabada, Anrich Nortje, Lungi Ngidi, Tabraiz Shamsi
Pakistan: Babar Azam (capt), Imam-ul-Haq, Fakhar Zaman, Mohammad Rizwan (wkt), Danish Aziz, Asif Ali, Shadab Khan, Faheem Ashraf, Shaheen Shah Afridi, Mohammad Hasnain, Haris Rauf
Umpires: Marais Erasmus, Adrian Holdstock (both RSA) TV umpire: Allahudien Paleker (RSA) Match referee: Andy Pycroft (ZIM)