Graeme Smith hit a brilliant half-century to put South Africa in a commanding position against Pakistan in the second and final test here at the Gaddafi Stadium on Wednesday.
Smith's unbeaten 75 and Jacques Kallis's 37 in a second innings score of 154-2 gave South Africa an overall lead of 305 when bad light stopped play on the third day.
The tourists dismissed Pakistan for 206 in their first innings.
Smith, whose team has not won a series in the subcontinent since 2000, hit 11 boundaries in his 233-minute knock to guide his team into a winning position.
Pakistan, bidding to level the two-match series, saw their main hope Inzamam-ul Haq falter in his final Test, scoring just 14 when the team looked to him to avert a large South African lead.
South African spinner Paul Harris said his team looked good to clinch the series after winning the first Test in Karachi by 160 runs.
"We are confident about our position in the Test. It is not an easy pitch to bat as it is definitely deteriorating and up and down for both spinners and seamers," he said.
Pakistan's chances of getting quick wickets when South Africa returned to bat were dented by an elbow injury to spearhead bowler Mohammad Asif.
Asif, who bowled 34 overs in the first innings, managed just four in the second before walking off.
"Asif was in pain in his elbow and he will have a MRI (scan) on Thursday to assess his injury," said team manager Talat Ali.
It left Pakistan, who entered the Test with just two frontline seamers and two spinners, severely depleted. Smith and Kallis took full advantage of the home side's miseries by adding 88 runs for the unbroken third wicket stand.
It built the innings after the loss of Herschelle Gibbs, caught behind off a wild shot on the bowling of fast bowler Umar Gul for 16.
Leg-spinner Danish Kaneria bowled Hashim Amla for 17 to leave the tourists at 66-2 before Smith and Kallis took charge.
Earlier, South African paceman Makhaya Ntini took three wickets in an over to help South Africa take a big first innings lead of 151.
Ntini's burst, in his second over of the day, included the wickets of Misbah-ul Haq (41), Gul and Kaneria without scoring as Pakistan lost their last six wickets for just 66 runs after resuming at 140-4.
Pakistan's main hope rested on Inzamam who survived just five deliveries before edging seamer Kallis to wicket-keeper Mark Boucher.
The 37-year-old batsman now needs just six runs in the next innings to erase the record of the most Test runs by a Pakistani batsman currently held by Javed Miandad with 8,832.
Captain Shoaib Malik did not last long as he failed to keep a sharp rising delivery from paceman Dale Steyn and was caught at short-leg by Amla for just one.
Misbah, who made a career-best 41, added 39 runs for the seventh wicket with Rehman (25 not out) before Ntini ended any hopes of a late-order charge.
Ntini almost took a hat-trick. He dismissed Haq, who improved on his best Test score of 23, caught behind off a rash drive outside the off-stump.
He then trapped Gul with his second delivery and then came agonisingly close when an edge off Kaneria fell short of the slips fielder. Off his sixth, Ntini had Kaneria caught by Boucher for his 400th victim.
Boucher set a world record for the most dismissals behind the stumps in the first Test in Karachi, beating Australian Ian Healy's record of 395.
South Africa 357 (A. Prince 63, J. Kallis 59, M. Boucher 54; Danish Kaneria 4-114)
Pakistan 1st innings (overnight 140-4)
|Salman Butt||c Smith b Harris||40|
|Kamran Akmal||c Smith b Harris||52|
|Younis Khan||b Nel||3|
|Mohammad Yousuf||lbw b Steyn||25|
|Inzamam-ul Haq||c Boucher b Kallis||14|
|Misbah-ul Haq||c Boucher b Ntini||41|
|Shoaib Malik||c Amla b Steyn||1|
|Abdul Rehman||not out||25|
|Umar Gul||lbw b Ntini||0|
|Danish Kaneria||c Boucher b Ntini||0|
|Mohammad Asif||c Amla b Harris||4|
Fall of wickets: 1-90 (Butt), 2-93 (Younis), 3-99 (Akmal), 4-123 (Yousuf), 5-149 (Inzamam), 6-150 (Malik), 7-189 (Haq), 8-189 (Gul), 9-189 (Kaneria).
South Africa 2nd innings:
|G. Smith||not out||75|
|H. Gibbs||c Akmal b Gul||16|
|H. Amla||b Rehman||17|
|J. Kallis||not out||37|
|Total:||(for two wickets)||154|
To bat: A. Prince, AB de Villiers, M. Boucher, A. Nel, P. Harris, D. Steyn, M. Ntini
Fall of wickets: 1-34 (Gibbs), 2-66 (Amla)
Umpires: Mark Benson (ENG) and Simon Taufel (AUS)
TV umpire: Nadeem Ghouri (PAK)
Match referee: Alan Hurst (AUS)