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 semifinal place with their fifth win in six matches.
The win also took South Africa to the top of the table, while Pakistan are on the brink of elimination with just two wins from six games.
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 Tabraiz Shamsi hung on to settle the tense contest.
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.
Brief scores: Pakistan 270 in 46.4 overs (Saud Shakeel 52, Babar Azam 50; Tabraiz Shamsi 4/60) lost to South Africa 271/9 in 47.2 overs (Aiden Markram 91, Shaheen Afridi 3/45, Mohammad Wasim Jr 2/50).
Player of the match: Tabraiz Shamsi