Aidan Markram and Rassie van der Dussen have produced patient half centuries, but Pakistan grabbed three late wickets, as South Africa reached 187/4 in their second innings on day three of a see-saw first test in Karachi.
The tourists lead by 29 runs and have wiped out a first-innings deficit, after they trailed by 158, after bowling Pakistan out for 378.
Captain Quinton de Kock has yet to score and will resume on the fourth morning with nightwatchman Keshav Maharaj (2 no), the pair looking to push South Africa towards a total that will give them something to defend in Pakistan's fourth innings.
Their situation looked a lot brighter 30 minutes before the close of play, but Pakistan's spinners grabbed three big wickets, as the shadows lengthened on the day.
Markram (74) put on 127 for the second wicket with Van der Dussen (64) to get their team into the lead, but the latter was caught at silly mid-off by Abid Ali, from the bowling of leg-spinner Yasir Shah (3/53).
The tourists were dealt a further blow, when Faf du Plessis (10) was trapped leg before wicket by the dangerous Shah, but worse was to come, as the set Markram was dismissed in the next over, also caught at silly mid-off, though from the bowling of Nauman Ali.
Opener Dean Elgar (29) was the other wicket to fall, after taking a nasty blow on the hand. He never looked settled after that and was caught by wicketkeeper Mohammad Rizwan, off Yasir. X-rays have revealed no fracture.
Pakistan's lower order frustrated the visitors in the morning session, as they took the attack to the bowlers.
After they resumed on 308 for eight, seamer Kagsiso Rabada (3/70) picked up his 200th test wicket, when he bowled Hasan Ali (21), becoming the fourth youngest player to reach the milestone.
But the final Pakistan pair of Yasir (38 not out) and Nauman (24) added 55 for the final wicket, before the latter was leg before wicket to spinner Maharaj (3/90).
South Africa will play two tests and three Twenty20 Internationals on their tour, their first in Pakistan since a militant attack on the Sri Lanka team bus in Lahore in 2009, in which six policemen and two civilians were killed.