Centuries by Younis Khan and Asad Shafiq transformed Pakistan's fortunes on the first day of the second Test against South Africa at Newlands on Thursday.
Pakistan were 253 for five at stumps, having been reeling at 33 for four after being sent in.
Younis was caught behind off Vernon Philander 13 balls before the close for 111, while Shafiq was unbeaten, also on 111.
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.
"After the first Test match we had a lot of meetings and chats about how we play Test cricket," said Younis.
"It was tough again this morning but everyone knows that if you have a good partnership you have a good chance to come back.
"It is all about the partnership and how you motivate yourself again and again and fight for your country."
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.
Younis, Pakistan's most experienced batsman, had to survive some challenging deliveries from Steyn at the start of his innings, and admitted: "I was lucky, I played a few balls and missed."
Shafiq followed a fighting half-century in the second innings in Johannesburg with an innings which grew in quality the longer it progressed.
"Asad Shafiq is improving every day, he has a good future for Pakistan," added Younis, who also said he had encouraged the younger player by advising him to play his natural game.
"My theory is very simple. If there is a ball (to hit), go for it."
It was slow going at times, with Younis and Shafiq adding only 14 runs in the first 13 overs after lunch.
The 50 partnership was posted off 151 balls, but their second 50 was scored off 88 deliveries and the pair scored freely in the afternoon before the second new ball was due.
Younis reached his 21st Test century - and his fourth against South Africa - after facing 192 balls and hitting six fours and three sixes, all of the sixes coming off left-arm spinner Robin Peterson.
The stocky Shafiq followed in the last over with the old ball, notching his third Test hundred off 201 balls with 13 fours and a six.
Steyn appeared to have made a breakthrough with his third delivery with the new ball when Younis, on 105, was adjudged leg before wicket by umpire Steve Davis.
But the batsman immediately called for a review which showed that the ball flicked the inside edge of his bat before crashing into his front pad.
Younis then fell victim to a successful review by South Africa after being given not out by umpire Bruce Oxenford. Replays showed he had been caught behind off an inside edge and his thigh pad.
Philander said he felt that South Africa had bowled well.
"The wicket is pretty good," he said.
"We knocked over four quite quickly, then Younis and Shafiq played very well. Overall it was a good bowling performance."
The Younis-Shafiq stand lasted for 439 balls and gave Pakistan heart after a poor start.
Opening batsmen Mohammad Hafeez and Nasir Jamshed started cautiously, scoring just ten runs before the left-handed Jamshed was caught behind off Philander for three.
He had survived a chance to Faf du Plessis at gully off the previous delivery.
Hafeez edged Steyn to first slip after making 17 before the tall Morkel took two wickets in an over, having Azhar Ali caught behind attempting an extravagant drive before Pakistan captain Misbah-ul-Haq was caught at short leg off a sharply rising delivery.