The pair put on 219, a record partnership for any wicket by Pakistan against South Africa.
It was a remarkable turnaround after the South African fast bowlers scythed through their top order early in the day.
Pakistan seemed in danger of another humiliation following their dismissal for a record low of 49 on the way to a 211-run defeat in the first Test in Johannesburg.
Graeme Smith's decision to bowl was prompted by cloudy weather, which followed early morning rain.
It seemed fully justified as Morne Morkel took two wickets and Philander and Dale Steyn claimed one each, with none of the batsmen looking comfortable.
Brief scoresPakistan 253/5 in 90 overs (Younis Khan 111, Asad Shafiq 111*, V Philander 2/45, M Morkel 2/37)