Pakistan were 412-8, still 172 runs adrift of overhauling the Proteas first innings score of 584-9.
South Africa looked set to force an early end to the innings on a very flat pitch when Dale Steyn managed to get Misbah-ul-Haq leg before on the first ball of the day.
Umar Gul went soon after, leg before wicket trying to sweep Paul Harris. However Rehman and debutant Ahmed ensured Pakistan passed the follow-on target, giving its tired bowlers some important rest.