Babar raised his 16th Test half-century and was unbeaten on 77 with a dozen boundaries while left-handed Alam continued his rich batting form to be 42 off 138 balls at tea. They did not resume as rain washed out the last session.
Pakistan was in trouble early after left-arm spinner Keshav Maharaj took two wickets in 10 balls and fast bowler Andrich Nortje had Abid Ali caught at forward short leg.
But Babar and Alam put the innings back on track with an unbroken 123-run stand as the ball got older in the middle session on a dry pitch which eased out for batting.
Babar caressed the offside field through some crisp cover drives, and was equally good off his back foot against the three fast bowlers.
Maharaj bowled the bulk of the overs, his 25 conceding 51 runs for two wickets.
“With the newish ball and the moisture, the ball sort of sticks in the wicket a little bit more,” Maharaj said of his early strikes. “As the day went on and the moisture sort of seeped away from the surplus surface, the turn was minimized substantially.”
The Pakistan skipper completed his fifty with a flicked boundary off Wiaan Mulder — the only change the Proteas made from the team which lost the first Test by seven wickets at Karachi last week.
“Credit to Babar and Fawad Alam, they absorbed the pressure nicely,” Maharaj said. “After lunch it seems to be easier to bat on the wicket, so fair play to them.”
Alam scored a gritty century in the first Test and continued to frustrate South Africa with his open chested batting stance.
South Africa had an injury scare when spinner George Linde left the field in the first session after the left-arm spinner tried to stop a hard drive off Babar off his own bowling. Linde didn’t sustain a fracture but required stitches on his little finger.
Linde didn’t return to the field in the middle session and South Africa management said he was subject to further testing.
Earlier, Proteas’ skipper Quinton de Kock read the dry pitch well as the visitors snapped up three wickets for one run within four overs after Babar won the toss and elected to bat.
Maharaj could have dismissed Imran Butt off his first ball only to see Temba Bavuma miss a regulation slip catch. But Maharaj, who got plenty of spin and awkward bounce off the pitch with the new ball, struck in his third over and the eighth of the day when Butt, on 15, got a thin edge and de Kock hold onto a sharp catch behind the wickets.
Azhar Ali struggled for nine deliveries and fell for a duck when Maharaj trapped the former Pakistan skipper off a full-pitched delivery that skidded through the right-hander.
Aiden Markram then snapped up a sharp reflex catch of Abid Ali on 6 at forward short leg off Nortje’s short-pitched delivery to have Pakistan 22-3.
But Babar and Alam then combined in a century stand and took the home team to 63-3 by lunch. They added 82 runs in the middle session.
Pakistan retained the playing XI which won the first Test. Left-arm spinner Nauman Ali, who became the oldest Test cricketer in 72 years to take a 5-for in an innings on debut, got another chance on a dry pitch similar to Karachi. Nauman, 34, and legspinner Yasir Shah shared 14 wickets.
South Africa brought in fast bowling allrounder Mulder, who played two home tests against Sri Lanka. Mulder replaced Lungi Ngidi.