Pakistan will have to fight hard to save the first Test against South Africa after a masterly knock of 155 by Jacques Kallis put the tourists in command at the National Stadium here on Tuesday.
At the close on the second day, Pakistan were 127-5 in reply to South Africa's first innings total of 450, still needing a further 124 to avoid the follow-on.
Captain Shoaib Malik was unbeaten on nine and Abdul Rehman one not out after a reckless display of batting by the home batsmen.
Pakistan lost four wickets for 26 runs after they were given a solid start by Kamran Akmal (42) and Mohammad Hafeez (34), who shared a 71-run partnership for the first wicket.
Left-arm spinner Paul Harris removed both the openers, trapping Akmal leg-before and then forcing an edge off Hafiz, which was smartly snapped up by Kallis in the slips.
Younis Khan had made only six before he was bowled by paceman Andre Nel off a delivery that kept low, while Kallis proved his all-round abilities by bowling Faisal Iqbal (seven) to leave Pakistan tottering at 97-4.
Malik and Misbah-ul Haq added 23 runs before a reckless shot off a wide delivery from Dale Steyn brought Haq's downfall, caught behind by Mark Boucher for 23.
Earlier, the South African innings was built around a brilliant knock by Kallis, who led his team to their highest total in Pakistan, surpassing the previous best of 403 they scored at Rawalpindi in 1997.
Kallis hit 19 boundaries during his five-hour innings and shared a valuable 170-run third wicket stand with Hashim Amla (71). He also shared a fourth wicket stand of 73 with Ashwell Prince.
South Africa, resuming at 294-3, added another 50 runs before Danish Kaneria struck twice to raise hopes of a fightback from the home team.
The leg-spinner, who was unlucky not to get Kallis on the first day when wicket-keeper Akmal dropped a catch when the South African maestro was on 36, finally got the prized scalp, his 199th in Tests.
Kallis was undone by the bounce and was caught behind while forcing a cut. He termed his hundred as one of his three best.
"It's right up there, maybe one of the three best I have made," said Kallis. "We were probably 50 runs short but the way the guys bowled is remarkable and put us in a strong position."
"There is still hard work ahead of us as the pitch is still good for batting."
Kaneria landed his 200th Test wicket when Prince failed to keep a drive on the ground and the leg-spinner took a straightforward catch in his follow-through.
Kaneria, playing his 47th Test, is the sixth Pakistani bowler to take 200 or more wickets in the longer version of the game.
When it seemed that South Africa might not reach 400, AB de Villiers hit a rapid 77 with seven boundaries and a six off 101-balls. He was the last man out, bowled by paceman Umar Gul, who finished with 2-60.
Debutant left-armer Rehman mopped up the lower order, taking four wickets in just 35 balls. He removed Boucher (one), Nel (two), Harris (one) and Steyn (nought) before Gul took the final wicket.
Rehman was the pick of the home bowlers with 4-105.
Pakistan, who were hit by the last-minute withdrawal of prolific batsman Mohammad Yousuf on Monday, received another blow on the second day when vice-captain and opener Salman Butt was hospitalised due to gastroenteritis.
Butt was released from the hospital and will bat on the third day.