Aiden Markram cracked a crucial half-century as table-topping South Africa broke their 24-year World Cup jinx against Pakistan with a nervy one-wicket victory and inched closer to securing a semi-final place with their fifth win in six matches.
South Africa began well chasing 271 as Quinton de Kock (24) and Temba Bavuma (28) landed early blows before Pakistan struck back with timely wickets, but Markram (91) held his nerve to take them close and they eventually got home in 47.2 overs.
Usama Mir (2/45) came on as a concussion substitute after Shadab Khan hurt himself fielding and he got rid of Rassie van der Dussen and took a catch to dismiss Heinrich Klaasen while David Miller (29) and Marco Jansen (20) departed after cameos.
But the Proteas would not be denied a first victory batting second in the event despite Markram falling to Usama and Gerald Coetzee to Shaheen Afridi (3/45), as Keshav Maharaj and player of the match Tabraiz Shamsi hung on to settle the tense game.
Pakistan fell to their fourth successive defeat as Maharaj hit a four off his legs but Haris Rauf (2/62) nearly won it for them towards the end with a diving catch to send back Lungi Ngidi before number 11 Shamsi survived a review for lbw.
"It's a bit of chaos (in the dressing room) at the moment, the guys are enjoying the moment, guys picking up Shamsi," said South Africa skipper Bavuma. "Nail-biting finish, if you're a South African fan, you're a little bit happier with the outcome.
Bavuma said slipping to 250/8 after looking comfortable at one stage was a problem of South Africa's own making and added that they would need to address their issues.
"There's obviously been pressure with us chasing," he said. "We haven't done well to rectify that. We'll have conversations. It'll be easier to have those conversations now with the win."
Pakistan were in trouble at 141/5 but Saud Shakeel (52) and Shadab (43) stitched together an 84-run stand with some powerful strokeplay at the MA Chidambaram Stadium to guide the 1992 champions to 270 all out in 46.4 overs.
Pakistan were undone at the end by the impressive Shamsi (4-60) and Gerald Coetzee (2-42), who dismissed the in-form pair, as they ultimately fell short of an imposing total when Mohammad Nawaz (24) threw his wicket away.
They were earlier pegged back following an early double strike by Jansen (3/43) after Babar won the toss and opted to bat but Mohammad Rizwan (31) steadied their innings with the skipper before falling to a bouncer from Coetzee.
South Africa ended another blossoming partnership as Shamsi got rid of the aggressive Iftikhar Ahmed (21) when he looked to raise the tempo during the middle overs, shortly before Babar brought up his third half-century of the tournament.
But Babar failed to swell his tally and he gloved a Shamsi delivery back to wicketkeeper Quinton de Kock while attempting a rash sweep as South Africa's hopeful review paid off to leave Pakistan needing another rescue act.
"Very disappointing for all the players," said Babar. "We fought back but we were 10 to 15 runs short and didn't finish well. The way fast bowlers and spinners bowled, they fought well but unfortunately the result was not in our hands.
"We had the opportunity to win this match and stay in the tournament but we missed it. We will try our best in our next three matches and put our effort in every match so let's see where we stand after the three matches."
Did this DRS review cost Pakistan the match?
Will India Play 3 Spinners Against England?
Gill tackles short ball as Team India sweats in nets
5 Biggest World Cup Victories
Is Gambhir Taking Another Shot At Dhoni?