Dale Steyn became South Africa's leading Test wicket-taker and Duanne Olivier took career-best figures as Pakistan were bowled out for 181 on the opening day of the first Test on Wednesday.
But the visitors mounted a spirited fightback with the ball, reducing South Africa to 127 for five at the close. Top scorer Themba Bavuma (38 not out) and nightwatchman Steyn (13 not out) will resume on day two with the hosts still trailing by 54 runs.
South Africa ripped through Pakistan after being asked to bowl by visiting captain Sarfraz Ahmed as Olivier, in the side for the injured Vernon Philander, claimed 6-37 with his pace and accuracy on a wicket already showing variable bounce.
But the headlines will revolve around Steyn, who had opener Fakhar Zaman (12) caught at slip by Elgar to move to 422 Test wickets, taking outright top spot on South Africa's all-time list ahead of Shaun Pollock. He was hoisted on the shoulders of fast bowling partner Kagiso Rabada as the healthy Boxing Day crowd at Centurion Park gave him a standing ovation.
The visitors were in early trouble when Rabada (3-59) had Imamul Haq trapped lbw for a duck.
After Steyn (1-66) had removed Zaman with the score on 17, Pakistan moved past 50 before Shan Masood (19) played the ball on to his own stumps off the impressive Olivier.
Asad Shafiq (seven) never looked comfortable at the crease and became Olivier's second victim as Pakistan took lunch on 76 for four. The fast-bowler ripped through the middle order after the break, removing Azhar Ali (36), Sarfraz (0) and Mohammad Amir (1) in quick succession.
Pakistan were reduced to 111 for eight but mounted an excellent fightback through Babar Azam (71 from 79 balls) as he put on 67 for the ninth wicket with Hasan Ali (21 not out) before being caught at second slip by Faf du Plessis off Rabada.
Pakistan continued their turnaround with the ball as they reduced the home side to 43 for four when Shaheen Afridi (2-36) took the wickets of Dean Elgar (22) and home captain Du Plessis (0) off successive deliveries, both off the edge of the bat.
Aiden Markram (12) and struggling Hashim Amla (8) also fell to high-quality fast bowling from Hasan and Amir, who picked up the wicket of Theunis de Bruyn (29) late in the day.