Postpublished at 13:38 British Summer Time 27 October 2023
Tabraiz Shamsi led South Africa's fightback in the final 10 overs though, finishing with 4-60, before Lungi Ngidi took the final wicket to leave Pakistan 270 all out with 3.2 overs unused.
South Africa win by one wicket - last-wicket pair putting on 11 to seal nervy win
Proteas had collapsed from 206-4 to 260-9
Markram anchors South Africa run-chase but falls for 91
Pakistan fail to bat out their overs; falling to 270 all out
Babar (50) and Shakeel (52) hit half-centuries but fail to kick on
Shamsi takes four wickets with Jansen taking three
South Africa go top of table with win
Ffion Wynne, Timothy Abraham and Jonty Colman
Tabraiz Shamsi led South Africa's fightback in the final 10 overs though, finishing with 4-60, before Lungi Ngidi took the final wicket to leave Pakistan 270 all out with 3.2 overs unused.
But Saud Shakeel counter-attacked with a partnership of 84, leaving South Africa a little short of answers and 300 looked on the cards.
It's been quite a frustrating tournament for captain Babar Azam, who has shown glimpses of magical form but hasn't been able to kick on to the big scores that Pakistan need from a player of his quality.
His departure left Pakistan in a bit of a pickle at 141-5.
Let's take a quick recap before South Africa begin their chase of 271.
Both Pakistan openers fell to the ever-impressive Marco Jansen, before Gerald Coetzee broke a threatening partnership between Babar Azam and Mohmmad Rizwan to leave the innings teetering at 86-3.
Jansen finished with figures of 3-43 in the end.
Pakistan batter Saud Shakeel: "The ball was gripping slightly for the spinners but I was happy to take my chances and back my strengths, which was playing the sweep shot mostly. Very happy to contribute some runs.
"I didn't know much about that [the change in the batting order] but I will do whatever job is asked of me. I back my strengths and I know what was expected of me.
"The shorter boundary was a bonus so I did plan accordingly with that. You can take a few more risks.
"This pitch is slightly different from the last one. The ball is bouncing a bit more so I think we've got a good total. We need early wickets and keep the pressure on them.
"I think we have got this. I am confident that is a good score."
Carlos Brathwaite
Ex-West Indies all-rounder on BBC Test Match Special
From where Babar Azam got out, they definitely would have taken 270. But then with the partnership Saud Shakeel and Shadab Khan had, they would wanted to eek closer to 300.
Wasim c De Kock b Ngidi 7 (Pak 270)
And that is that.
Pakistan are all out for 270.
Lungi Ngidi wraps up the innings as Mohammad Wasim takes a big swing and gets a faint edge through to the keeper.
An entertaining innings, as it so often is with Pakistan, with half-centuries for Babar Azam and Saud Shakeel taking the headlines, supported by Shadab Khan's 43.
We're having a chat about Haris Rauf's batting average, which is 4.7.
I just love a genuine number 11. There aren't enough of them any more. Always guaranteed entertainment.
Mohammad Nawaz wasn't there for long, but he made sure we were entertained nevertheless.
Carlos Brathwaite
Ex-West Indies all-rounder on BBC Test Match Special
I thought that was a slower ball, it looked like one. Nawaz went into the shot quite early, David Miller can call it as soon as it goes up. It is the level of fielding, the catching has been spot on. The fielding has had a couple of generations of this now when you think back to the likes of Jonty Rhodes.
With 268. you think this is well short of a modern competitive total.
Big talent, Marco Jansen. Having a great tournament.
He has 3-43 so far.
Nawaz c Miller b Jansen 24 (Pak 268-9)
Nine down!
Mohammad Nawaz's cameo comes to an end for a run-a-ball 24 as he slogs Marco Jansen high in the air. David Miller steadies himself underneath it and takes a very smart catch under a swirling ball under the dark sky.
Pakistan are in danger of wasting precious balls at the death here.
He gets important wickets, too. Here's how Saud Shakeel fell for 52.
Well, there's no five-for, as Shamsi is whacked for six instead to conclude his spell.
Heck of a shot from Wasim, one-legged with a swish of the bat like a helicopter for six.
Still, a fine spell of 4-60 from the leg-spinner. He was expensive at times but those wickets are what he's in the side for.
Russel Arnold
Former Sri Lanka all-rounder on BBC Test Match Special
That's a little bit disappointing for Shaheen Shah Afridi to go out for just two, but that's great captaincy to put a slip in place there.
Nikesh Rughani
BBC Test Match Special commentator
Shamsi gets another. Shaheen tries to play straight and he is nicked. Pakistan are in real danger of not batting 50 overs.
Shaheen c Maharaj b Shamsi 2 (Pak 259-8)
Shamsi has his fourth! It's beautifully bowled too, a hint of turn just taking Shaheen Afridi's outside edge and a comfortable catch for Keshav Maharaj at slip.
Great captaincy from Bavuma to have the slip in the 44th over.
Can Pakistan avoid being bowled out here? Shamsi has five balls left to try get his five-wicket haul.
We could be in for some fun if Nawaz sticks around for the last six overs.
Oooh, costly from Marco Jansen.
The ridiculously tall fast bowler starts nicely but gives away two wides at the end, and the extra ball is carved for four.
Mohammad Nawaz is playing a very handy cameo of 23 from 20 balls so far.
Russel Arnold
Former Sri Lanka all-rounder on BBC Test Match Special
That shot from Nawaz broke the shackles. If I'm Babar Azam, I'm saying don't force anything too much and try and bat out the overs.