Hashim Amla's 20th Test century kept South Africa afloat on the opening day of the series against Pakistan in Abu Dhabi.
Amla hit 118 not out in a total of 245-8, leading the tourists out of early trouble before a late collapse handed the initiative back to Pakistan.
South Africa slumped to 40-3 after opting to bat first, Mohammad Irfan taking out openers Alviro Petersen (3) and Graeme Smith (15) in his opening spell.
Irfan's new-ball partner Junaid Khan (1-52) claimed the big wicket of Jacques Kallis, caught behind for five via an inside edge.
Amla and AB de Villiers steadied the innings with a 61-run stand for the fourth wicket either side of lunch.
The partnership was ended by a run out; Pakistan wicketkeeper Adnan Akmal noticed De Villiers had not regained his ground after an inside edge went to Younus Khan at slip and, after Younus returned the ball, he removed the bails.
After several replays the third umpire ruled De Villiers had not managed to get back behind the line and he was given out for 19.
It was the second time English video umpire Ian Gould had been called to rule on a dismissal, having played the pivotal part in Smith's wicket.
Pakistan claimed a catch behind in the seventh over and, after initially being given not out, the left-hander was sent back to the pavilion after Gould decided he had edged Akmal, with television replays suggesting there had been a sound as the ball passed the outside edge.
Amla and JP Duminy took South Africa through to tea on 152-4 and extended their fifth-wicket alliance to 95 before Pakistan's 34-year-old debutant left-arm spinner Zulfiqar Babar (3-89) struck three times in quick succession.
Duminy (57) picked out Asad Shafiq with a sweep, Faf du Plessis (1) edged to Shafiq in the gully and Robin Peterson (5) was bowled through the gate.
In the meantime, Amla had gone to three figures from 201 balls, including 11 fours.
Off-spinner Saeed Ajmal (1-57) won an lbw verdict against Vernon Philander, upheld on review, leaving Dale Steyn (13no) to join Amla through to stumps.
Pakistan handed first Test caps to Babar and batsman Shan Masood, on his 24th birthday, for the first of two Tests in the United Arab Emirates.
The series concludes in Dubai from October 23-27 and is followed by five ODIs and two T20 internationals.