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.
It was the Proteas' 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 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 in Chennai 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.