Pakistan were off to a confident start in their first innings after South Africa's Mark Boucher hit a fighting half-century on day two of the second cricket Test here.
The home team reached 51 at tea without loss with openers Salman Butt (30) and Kamran Akmal (21) batting fluently in reply to the tourist's total of 357 at the Gaddafi Stadium.
Butt looked in great touch as he hit paceman Dale Steyn for three boundaries while Akmal also struck one to take 19 off the fourth over and then help post the fifty in just the eighth over.
South Africa owed their total to a defiant 88-run stand, the highest of the innings, between Boucher (54) and Paul Harris who made a career-best 46.
Boucher was the last man out when he holed out at leg-spinner Danish Kaneria who was the pick of the home bowlers with 4-114. He hit Kaneria for a six to reach his 26th half-century.
Boucher's 132-ball knock, studded with four boundaries and a six, paved the way for the tourists' respectable total.
Pakistan had dismissed overnight batsman Andre Nel for nought off the fifth ball of the day when paceman Umar Gul had him caught fending a short delivery. South Africa had lost Nel on their overnight total of 259.
The home team's efforts to wrap up the South African innings early and to build on their advantage of the first day were quashed by Boucher who combined with Harris to frustrate the home attack.
Harris showed remarkable guts as the tail-ender improved his best Test score of 11 made against India in Cape Town earlier this year.
He negotiated Gul and Mohammad Asif well and twice swept Danish Kaneria to the square-leg boundary to help the tourists reach lunch at 322-7.
Pakistan captain Shoaib Malik once again did not use left-arm spinner Abdul Rehman until half-an-hour before lunch.
It was finally Gul who broke the stubborn stand when he had Harris driving uppishly and was caught by Malik in the covers. Harris hit six boundaries during his resolute 160-minute knock.
Gul finished with 3-103.