Imran Tahir's maiden five-wicket Test haul and an unbeaten 67 from Graeme Smith helped put South Africa well on top after a dramatic first day of the second Test against Pakistan in Dubai.
The hosts were skittled out for just 99 before South Africa reached 128-3 at the close, with Smith well set and eyeing a possible 27th Test century on Thursday.
But it was Tahir who did the damage earlier after replacing Robin Peterson in the side and taking 5-32.
Dale Steyn, passed fit after a hamstring strain, chipped in with 3-38, before Smith led from the front with the bat.
Pakistan entered the game with a 1-0 lead in the two-Test series but they made a poor start when Khurram Manzoor was out without a run on the board.
Manzoor went for a flamboyant cover drive from an outswinging ball from Steyn, getting a thick edge which flew to Faf du Plessis at gully.
Pakistan were making patient progress and had reached 38 when Azhar was lbw coming forward to to Morne Morkel, replays showing the the ball would have clipped leg stump.
Pakistan were then reduced to 52-3 when Masood was bowled by Tahir after making 21 off 60 deliveries.
Pakistan were wobbling and things went from bad to worse when they lost three wickets for no runs after reaching 60.
Younis Khan was first to go for 10 off a full delivery from Steyn which the batsman pushed lamely to AB de Villiers for a simple catch.
Tahir then claimed his second wicket three balls later when Misbah-ul-Haq was caught low on the pad to be lbw for just two.
Tahir bowling superbly and three deliveries later he claimed his third wicket of the session when his full ball to Adnan Akmal clipped leg stump.
The batsman was out for a duck and had faced just three balls, lunch coming to Pakistan's rescue after a miserable first session.
However, it was merely a prelude to more powerful attack from Tahir and Steyn.
With just four more runs on the board, Saeed Ajmal was run out for a duck as Alviro Petersen hit the stumps with the batsman well short.
Pakistan were limping along and Tahir struck twice in three deliveries, as he bowled both Asad Shafiq (10) and Mohammad Irfan (nought) as Pakistan reached 76-9.
It was a case of when not if for Pakistan and although Zulfiqar Babar (25no) and Junaid Khan managed to move the score on to 99, Steyn struck for the third time, his delivery to Junaid (four) taking out middle stump.
South Africa moved steadily in their response and had reached 37 when Petersen was out lbw to Babar after making 26 from 36 deliveries including four boundaries.
Dean Elgar joined Smith at the crease and the pair had shared a stand of 54 when the former was out for 27, getting an inside edge off an Ajmal delivery with the ball flying to Azhar Ali who made a low, clean catch at short leg.
Smith's partnership with Jacques Kallis was soon cut short when Ajmal got his second wicket, the South African caught lbw after making seven, but it is the tourists who look set to take charge of the game on day two.