The match seemed headed for an early finish when the first four wickets fell for 82 runs, but Pakistan captain Misbah (44 not out) and the stocky Shafiq (53 not out) defended grimly for more than three hours, adding an unbeaten 101.
South Africa remained in a strong position to take a 1-0 lead in the three-match series, however, with a second new ball due after five overs and only wicketkeeper Sarfraz Ahmed of the remaining batsmen likely to offer resistance.
Brief Scores: SA 253 & 275/3d (de Villiers 103no, Amla 74no) vs Pak 49 & 183/4 (Shafiq 53no).