Pakistan's pace-cum-spin attack caught world number one Test team South Africa napping on the third day of the first Test in Abu Dhabi on Wednesday.
South Africa lost four top-order batsmen against a spirited Pakistan and now need another 121 runs to avoid an innings defeat at Sheikh Zayed Stadium and concede the lead in the two-Test series.
AB de Villiers was unbeaten on 11 and with him nightwatchman Dale Steyn on nought on a day when Pakistan captain Misbah-ul Haq scored his fourth Test hundred and then sent his rivals into submission.
Pakistan removed Alviro Petersen (17), Graeme Smith (32) and Jacques Kallis (nought) by the 19th over and then first innings centurion Hashim Amla for ten to move closer to a big victory when bad light curtailed play seven overs early.
Paceman Mohammad Irfan started aggressively, trapping Smith in front off the very first ball of the innings but Pakistan's referral was unsuccessful after the umpire initially ruled it not out.
But Irfan struck in his sixth over when a rising delivery caught Petersen by surprise, the batsman failing to keep his glove out of the way before Adnan Akmal held the catch cleanly.
Smith looked confident during his 61-ball knock but missed one delivery from Saeed Ajmal and was stumped on the second attempt by Akmal, leaving South Africa at 57-2.
With Smith's scalp, Ajmal completed his 150 wickets in 29 Tests -- joint fourth fastest to reach the milestone and second Pakistani behind paceman Waqar Younis, who completed the tally in 27 Tests.
A run later Kallis was trapped in front of the wicket by fast bowler Junaid Khan for a five-ball duck, spoiling the most reliable South African batsman's comeback and 38th birthday.
Amal, who hit 118 in the first innings, fell caught behind off left-armer Zulfiqar Babar's first delivery in the innings to leave South Africa tottering at 72-4.
Earlier Misbah ensured Pakistan increased the lead after opener Khurram Manzoor departed for 146, adding an invaluable 82 for the fifth wicket with Asad Shafiq, who made 54.
At 39 years and 141 days, Misbah became the oldest Pakistani batsman to score a Test hundred. He is also the oldest to notch a Test hundred since England's Graham Gooch reached the three-figure mark against New Zealand at Nottingham in 1994 at the age of 40 years 314 days.
England's Jack Hobbs holds the record for oldest Test centurion at 46 years and 82 days when he scored a hundred against Australia in 1929.
Manzoor, who resumed on 131, bettered Pakistan's highest individual Test score against South Africa, held by all-rounder Azhar Mahmood who scored 137 in Johannesburg in 1998.
But Philander gave South Africa the much-needed breakthrough by dismissing Manzoor, caught off a slash in the slip by Jacques Kallis.
Manzoor hit 15 boundaries and batted solidly throughout his 388-minute knock. He added 112 for the fourth wicket with his skipper to strengthen Pakistan's position.
Misbah reached his hundred with a single off Jean-Paul Duminy, his first after 16 Tests, off 185 balls, raising his arms and bat in acknowledgement. In all he batted for 298 minutes, hitting eight boundaries.
Steyn trapped Misbah leg before for 100 to finish with 3-88 after his first 23 overs went wicketless.
Duminy, who took 2-68, proved better than regular spinner Robin Peterson who remained wicketless after 27 overs, conceding 111 runs.
The second and final Test will be played in Dubai from October 23. The teams will also play five one-day and two Twenty20 internationals.