Pakistan batsmen Misbahul Haq and Asad Shafiq held up South Africa's push for victory with a defiant fifth-wicket partnership on the third day of the first Test at the Wanderers Stadium on Sunday.
Pakistan were 183 for four at the close after being set to make an improbable 480 to win.
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 on Monday and only wicketkeeper Sarfraz Ahmed of the remaining batsmen likely to offer sustained resistance to the South African fast bowlers.
Both Misbah and Shafiq had let-offs.
Shafiq edged an outswinger from Vernon Philander to Graeme Smith at first slip when he had 40 and the total was on 155.
Shafiq had almost reached the boundary edge when his dressing room alerted him to a television replay which showed that Philander had bowled a no-ball.
Four balls later, Misbah, on 31, sliced a drive against Jacques Kallis to backward point, but Robin Peterson, diving to his right, could not hold a waist-high chance.
Before Misbah and Shafiq came together everything had seemed to be going South Africa's way.
AB de Villiers hurried to a century before South Africa declared on 275 for three, leaving Pakistan with an hour's batting before lunch.
De Villiers needed only 33 balls to move from his overnight 63 to 103 not out.
He and Hashim Amla added 68 in nine overs before the declaration, which came immediately after De Villiers punched Umar Gul to the cover boundary to reach his 15th Test century off 117 balls. He hit 11 boundaries.
Amla was unbeaten on 74 off 114 balls with seven fours. The pair put on an unbeaten 176 for the fourth wicket, easily the best partnership of the match.
After being routed for their all-time low total of 49 in the first innings, Pakistan made a more confident start to the second innings.