South Africa were 187-4 at close on the third day of the opening Test against Pakistan in Karachi on Thursday, leading by 29 runs.
Keshav Maharaj was unbeaten on two and Quinton de Kock was yet to score as South Africa erased Pakistan's first innings lead of 158 with some brilliant batting at the National Stadium.
Pakistan scored 378 in reply to a South African first innings total of 220.
South African paceman Kagiso Rabada completed 200 wickets in Test cricket by dismissing Hasan Ali, becoming his country's eighth bowler to achieve the milestone.
South Africa are on Pakistan's first tour in 14 years where they are playing two Tests and three Twenty20 internationals.