Pakistan 274 for 7 (Babar 103, Imam 70, Nortje 4-51) beat South Africa 273 for 6 (van der Dussen 123*, Miller 50, Afridi 2-61) by three wickets

Babar Azam saw Rassie van der Dussen's first international hundred and raised him a century of his own before Anrich Nortje recorded a career-best 4 for 51, Mohammad Rizwan scored 40 off 52 balls in a partnership of 53 for the sixth-wicket with Shadab Khan, van der Dussen dropped Khan in the penultimate over, Lungi Ngidi bowled him off a waist-high full toss that was called a no-ball, the resultant free hit went for four, Pakistan needed three runs off the last four balls when Faheem Ashraf was hit on the helmet and required a concussion test, scores were level with one delivery to go and Pakistan won the opening ODI. Welcome to international captaincy Temba Bavuma.

With high drama lacing through Bavuma's first match in charge, he made some good decisions at the end of a tense chase and tasked Andile Phehlukwayo and Ngidi with bowling the death overs. They had 19 runs to defend off the final three and very nearly pulled off a memorable win. Instead, it was Ashraf who turned hero as he laced a wide one through point to seal victory off the last ball.

Things never looked like they would get that tense when Azam was at the crease in complete control of what seemed a straightforward chase. On a slower-than-usual SuperSport Park pitch, where almost every other batsman struggled to score fluently, Azam played a silken knock. He scored runs all around the wicket to bring up his 13th century and first against South Africa, at a run-a-ball. His 177-run second-wicket stand with Imam-ul-Haq broke the back of a target and Pakistan were cruising until Nortje's second spell.

Azam edged him to Quinton de Kock the ball after he reached his hundred to spark a mini-collapse. Pakistan were 186 for 2 at the 32nd over and needed 88 runs off 18 overs. But then, Imam miscued a pull to mid-on in Nortje's next over, Danish Aziz edged a short ball behind in the over after that and Asif Ali slogged Nortje to midwicket in the following over. Pakistan were 203 for 5 after 38 overs and needed 71 runs off 12 overs. Still doable, if Rizwan ushered them home.

He scored two boundaries off Nortje's final over, then Shadab pulled and hooked Kagiso Rabada and the pair seemed set to finish things off. But in the 48th over, Rizwan holed out to deep mid-wicket off a Phehlukwayo slower ball and things got complicated. Pakistan needed 14 off the last 12 balls and Ngidi bowled two dots before Ashraf took a single. Shadab swung wildly off at the fourth ball of the over to send a swirling chance to deep mid-wicket and van der Dussen made good ground to get under it but couldn't. Off the next Shadab got an outside-edge as he backed away from a full toss to attempt a big shot and chopped on but he signalled that the delivery was high and replays confirmed a no-ball. Ngidi had to deliver that again and went full so Shadab bisected cover and mid-off to get four. The over ended with an outside edge that went through de Kock and the batsmen ran three to leave them needing just three more off the last over.

Phehlukwayo had Shadab, for real, caught off the first ball by van der Dussen, then bowled a dot ball and then hit Ashraf with a bouncer as he missed the pull. Another dot followed before Ashraf chipped a slower ball over Phehlukwayo for two to level scores. A conference preceded the last ball, with the prospect of a super over looming, but Phehlukwayo offered too much width.

Ultimately, South Africa actually lost the match with the bat after Bavuma said he thought "a minimum of 280" would be required. South Africa only managed to drag themselves within 10 runs of it after being tied down for significant periods of their time at the crease. Pakistan reduced South Africa to 55 for 4 inside 15 overs and kept the run rate to under five for most of the innings. Van der Dussen and David Miller's fifth-wicket partnership of 116-run kept them ticking along before Phehlukwayo and van der Dussen added late innings impetus.

What South Africa lacked was the consistency of run-scoring that Azam provided after he arrived in the third over when Fakhar Zaman chopped a Rabada delivery onto this stumps. The first eight overs only produced 19 runs before Azam flicked Rabada to mid-on to signal his intent. He took two boundaries off Nortje's next over and was unstoppable from there.

Among his highlights was a front foot pull off Phehlukwayo, a punishing straight drive off a full toss from Nortje and routinely beating the boundary riders. His fifty came off 61 balls with a drive off Tabraiz Shamsi and his hundred, off 103 balls, with a clip off the pads against Nortje to cap off a superb skipper's knock.

By contrast, Bavuma had a forgettable first innings in charge. He was dismissed for a four-ball 1 after giving catching practice to Shaheen Shah Afridi at third man and deepened South Africa's early malaise. They lost both openers in the same over after a breezy start albeit with some difficulty timing the ball. Afridi accounted for de Kock, when he tried to clear the in-field but sent the ball straight to Azam at mid-off and Aiden Markram, who chipped a catch to Ashraf at mid-on.

Bavuma was dismissed in the next over and Heinrich Klaasen could have gone off the next ball when was given out lbw but reviewed immediately to reveal an inside-edge. Van der Dussen might have departed the over after that when Afridi found his outside edge but Asif Ali, at second slip, could not hold on to a tough chance. Van der Dussen had not scored a run at that stage.

Similarly, Azam was on 1 when Bavuma moved his second slip wide and Ngidi found his outside edge. Markram dived full length to his right and got fingertips to the ball but could not hold on. Doubtless, South Africa will rue their missed chance more.

Pakistan's drop was mid-strangle as they kept South Africa to 10 runs in five overs, for the loss of three wickets, and the batsmen struggled to get going. Van der Dussen's first run came off the eighth ball he faced, and Klaasen's only one off the 19th. Two balls later, he tried to cut Ashraf off the back foot but edged behind. Pakistan may have seen an opportunity to run through South Africa but the middle-overs meandered.

Haris Rauf, in his third ODI, was expensive, and Miller hit him out of the attack. Azam brought Afridi back in the 21st over to try and force a breakthrough, then turned to Mohammad Hasnain and eventually even to the debutant Aziz, who bowled three overs of left-arm spin, all without success.

Van der Dussen reached fifty off 80 balls with a cut off the back foot and Miller followed suit, off 52 balls and as they approached the final 15 overs, the pair would have been eyeing an acceleration. Miller couldn't make it happen and swished at a delivery that didn't bounce as much as he expected and edged Rauf to Rizwan, who took the catch even as the ball died on him.

Phehlukwayo wasted no time showing his intent and hit the first Rauf ball he faced over point for four but then reined in his early aggression. South Africa crawled to 200 in the 43rd over before deciding to let loose. Phehlukwayo hit an Afridi low full toss to long-on and then inside-edged him for four more before van der Dussen entered the nineties when he cleared the front leg to dispatch Hasnain for six. Phehlukwayo eventually fell to a Rauf slower ball but van der Dussen batted through and opened up after reaching his hundred. He scored 23 off the last 11 balls he faced and South Africa managed 68 off the last seven overs but it proved just short.

Firdose Moonda is ESPNcricinfo's South Africa correspondent