Pakistan batsmen Misbah-ul-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 and Mohammad Hafeez was somewhat unfortunate to fall to a diving catch by AB de Villiers when he glanced Philander to leg.
Nasir Jamshed and Azhar Ali put on 57 for the second wicket but tight bowling by Dale Steyn and Philander after lunch slowed the scoring rate down.
The left-handed Jamshed, playing in his first Test match, looked solid before he was out for 46 when he pulled Steyn tamely to midwicket.
Azhar followed three overs later for 18. Having been subjected to some hostile short-pitched bowling from Steyn he was trapped in front of his stumps when he played across a full delivery from Kallis.
Morne Morkel took his first wicket of the match when Younis Khan was caught behind for 15, nibbling at and then attempting to withdraw his bat from a fast delivery outside his off stump.