Runs were hard to come by for the two batsmen but they displayed patience and selected their shots carefully, extending the match into a fourth day.
Despite much posturing from the South African bowlers, all of which came to nought, Pakistan consolidated and applied themselves well, attacking the ball and leaving at the right times.
Vernon Philander thought he had broken the partnership when Shafiq, on 40, was caught at slip by Graeme Smith. The batsman was walking off until he saw his coach, Dav Whatmore, signalling frantically from the balcony to stop him. Television replays showed clearly the delivery had been a no-ball and umpire Bruce Oxenford was forced to reverse his decision.
In the next over, Robbie Peterson, fielding in the gully, dropped Misbah – off the bowling of Jacques Kallis – when he was on 31. Unfazed, Shafiq went on to reach his half-century off 117 balls, stroking nine fours, and the pair added 79 runs in the last session for no loss.
Pakistan still needed 297 runs to win but the partnership was not only important in delaying the inevitable, it should also give them some belief for the next two Tests, proving they are able to occupy the crease and withstand the formidable Proteas seam attack.
Mohammad Hafeez (two runs) fell early in the innings, looking to play Philander down the leg side, but instead getting an edge, as AB de Villiers took an outstanding catch.
Dale Steyn removed the other opener, Nasir Jamshed, whose pull shot went straight to Peterson at mid-on. It was a soft dismissal for the Test debutant after he had played so well for his 46 runs. His partnership with Azhar Ali lasted 107 deliveries and yielded 57 runs, including nine boundaries.
Ali lasted a couple more overs before he was trapped lbw to Kallis for 18. Younis Khan survived a review by the South Africans for a similar call but was less fortunate when he got a faint edge to a wider delivery from Morne Morkel, providing De Villiers with his eighth catch of the match. It was a key wicket for the hosts as partnerships and time at the crease had become paramount for the Pakistanis, and Younis would have done better to leave the wide delivery alone.
Earlier, South Africa declared their second innings at 275 for three, midway through the morning session, with a lead of 479 runs. Hashim Amla and De Villiers surpassed their own previous best fourth-wicket stand of 147 at the Wanderers.
They added 176 runs off 217 balls before skipper Smith waved them back into the pavilion. Smith waited for De Villiers to complete his 15th Test century – which came off 117 balls and included 11 boundaries – while Amla remained on 74 not out.
At stumps, Misbah was unbeaten on 44 and Shafiq on 53. – Sapa