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 and shared a second-wicket partnership of 177 with Imam-ul-Haq, who made 70. But Babar’s dismissal started a collapse in which fast bowler Anrich Nortje took four wickets in four overs.

From 186/1, with more than 18 overs in hand to reach a target of 274, Pakistan slumped to 203/4 before Mohammad Rizwan and Shadab Khan steadied the innings again in a sixth-wicket stand of 53.

But both were dismissed before Faheem Ashraf hit the winning run off Andile Phehlukwayo off the last ball.

“There was a little bit of pressure but we will learn from that,” Babar said through an interpreter at the after-match presentation.

Babar, who was named player of the match, praised his bowlers, who came within three runs of achieving his objective of restricting South Africa to a total of around 270 after he won the toss and sent them in.

“I told them to bowl hard lengths and there was some swing as well,” he said. “They took wickets in the power play and that helped us.”

Rassie van der Dussen had to perform a rescue act for South Africa after the hosts struggled to 55/4 inside 15 overs. He hit 123 not out, his maiden international century, to enable South Africa to score 273/6.

South African captain Temba Bavuma admitted the loss of early wickets disrupted South Africa’s aggressive intent.

“We didn’t help ourselves with our batting effort in the first ten overs,” he said.

The win gave Pakistan an important advantage in the three-match series, with South Africa set to lose five key players to the Indian Premier League after Sunday’s second match in Johannesburg.

Nortje, one of those who will depart for India, conceded 31 runs in his first spell of five overs but came back strongly, dismissing Babar and Iman in successive overs before having new cap Danish Aziz caught behind off a vicious, lifting delivery.

When Asif Ali was caught off a top-edged pull, South Africa were right back in the game. Nortje finished with four for 51.

Rizwan, who was man of the series in both Tests and Twenty20 clashes against South Africa in Pakistan earlier in the year, again showed a calm temperament as he and Shadab took their side close to victory.

But Rizwan and Shadab both perished to over-ambitious shots against the medium-paced Phehlukwayo as the match went down to the last ball.

Van der Dussen and David Miller (50) revived South Africa’s innings earlier with a fourth-wicket stand of 116. Van der Dussen and Phehlukwayo (29) then added 64 for the sixth wicket.

The 32-year-old Van der Dussen had been dismissed three times in the nineties – twice in one-day internationals and once in a Test match – since making his debut two seasons ago.

He took 80 balls to reach his fifty but lifted the tempo of his innings to finish with ten fours and two sixes off 134 balls.