Pakistan were dismissed for 185 in response to home side's first innings total of 262
South Africa were 135-5 and had a second innings lead of 212 runs at stumps on the second day of the third Test against Pakistan in Johannesburg.
At the close of play, a steady Hashim Amla along with wicketkeeper-batsman Quinton de Kock were unbeaten on 42 and 34 runs respectively, while their sixth wicket partnership had yielded crucial 42 runs.
Home side's fiery seamer Duanne Olivier took five wickets as the Proteas made heavy work of bowling Pakistan out for 185 in their first innings on day two of the third and final Test at the Wanderers on Saturday.
South Africa might have been much further ahead had they not had a poor opening session in the field when they dropped four fairly simple catches, missed a stumping and wasted two run-out chances - good fortune that Pakistan could not capitalise on.
In the second innings, stand-in South Africa captain Elgar (5) failed with the bat for a second time in the match when he edged to Sarfraz off Mohammad Amir.
Aiden Markram fell soon after tea — scoring 21 runs — as Sarfraz completed a brilliant catch behind the stumps off the bowling of Mohammad Abbas.
Theunis de Bruyn and Zubayr Hamza fell victim to Faheem Ashraf’s bowling in the same over — which left the home side reeling at 45-4.
At this point, Bavuma and Amla stitched an important 48-run stand for the fifth wickets to keep the home side in the ascendancy.
Bavuma (23) was dismissed by leg-spinner Shadab Khan when the score had reached 93.
Earlier the tourists resumed on their overnight score of 17 for two and rode their luck through the first hour as South Africa spilled opportunities behind the wicket, with opener Imamul Haq (43) the main beneficiary of the home side's profligacy.
Nightwatchman Mohammad Abbas (11) was also dropped twice off relatively simple opportunities and was eventually the first man out as Olivier (5-51) picked up two wickets in an over to end the home side's frustration.
Abbas was caught by Theunis De Bruyn at slip and three balls later Asad Shafiq (0) left his hands and bat above his head as he tried to duck a bouncer and edged to Quinton de Kock behind the stumps.
Imam's luck finally ran out when he steered a Vernon Philander (3-43) delivery to Dean Elgar at slip to leave the tourists on 111 for five at lunch.
Babar Azam (49) and captain Sarfraz Ahmed (50) then mounted an excellent fightback with a 78-run sixth-wicket partnership in only 10 overs before the latter edged seamer Kagiso Rabada (2-41) to Amla at second slip.
Olivier and Rabada cleaned up the tail with some hostile fast bowling that had the ball whistling past the chins of the Pakistan batsmen as the visitors lost their final five wickets for 16 runs.
Olivier now has 21 wickets in five innings in this series at an average of 13 against a Pakistan side who are unable to handle his pace and bounce.