Off-spinner Saeed Ajmal took all five wickets as Pakistan finished on top on a controversial second day of the second Test against South Africa at Newlands on Friday.
South Africa were struggling at 139 for five at the close, still 199 runs behind Pakistan's first innings of 338 after Ajmal had finished with five for 41.
"Pakistan are ahead of the game," admitted South African assistant coach Russell Domingo.
Pakistan coach Dav Whatmore admitted that his side should never have been written off despite being mauled by 211 runs in the first Test in Johannesburg.
"It's a totally different game in totally different conditions," he said
"The home team were not under much pressure at all in Johannesburg. Here they are confronted with a total of 300-plus on a wicket which is totally different. We are very pleased with the way this match is going so far."
Three of Ajmal's wickets came after the use of the decision review system, including a controversial dismissal of star South African batsman Jacques Kallis.
South Africa captain Graeme Smith and Hashim Amla were both out leg before wicket after being given not out by umpire Steve Davis.
Kallis was given out caught at short leg and immediately called for a review, which showed that the ball had not touched his bat before looping off his pad to the fielder.
But he was then given out leg before on the advice of television umpire Billy Bowden, although replays showed the ball was only brushing the outside of his leg stump, in the area known as "umpire's call".
South Africa team manager, Mohammad Moosajee, said that he had been satisfied with the explanation he had received.
"All we did was seek clarity from the umpire, which we were happy with," he said.
"The rule states that if an umpire has given a batsman out and the batsman appeals, he can be given out for something else."
Controversy apart, it was a superb display by Ajmal who bowled 25 overs unchanged into a stiff south-easterly wind, varying his flight and mixing off-spin with cleverly disguised top spinners and doosras which turned away from the right-handed batsmen.
It was a productive day for Ajmal, who helped fellow tailender Tanvir Ahmed put on 64 for the ninth wicket to take Pakistan comfortably past the 300 mark.
Their eventual total seemed unlikely when Vernon Philander took three wickets in his first three overs to reduce the tourists to 268 for eight.
"It was very important to get as many runs as we could on a pitch which we think will get more difficult to bat on," said Whatmore.
Ajmal came on after 11 overs had been bowled in South Africa's innings.
He struck with his ninth delivery when Smith missed a sweep and Pakistan successfully sought a review.
Two overs later Ajmal had Alviro Petersen smartly caught at short leg by Azhar Ali, who dived to his right to hold a sharp chance.
At tea, Ajmal had taken two for 20.
Hashim Amla went back on his stumps and was also given out on review before Kallis was dismissed.
He was followed by Faf du Plessis, caught at slip off a doosra for South Africa's highest score of 28.
AB de Villiers and Dean Elgar survived until the close.
Domingo said Ajmal had proved he was a "quality bowler" and had taken advantage of a pitch on which he was able to get some purchase.
"Maybe the wicket has been a bit drier than we thought it would be and maybe our guys were a bit too tentative," he said.
"It is something the guys will think long and hard about and hopefully employ some of that in the second innings."
Pakistan batted until lunch after resuming at 253 for five, although Philander's early strikes raised the home side's hopes of wrapping up the innings quickly.
Philander took five for 59, his ninth five-wicket haul in Tests.