Ajmal grabbed five wickets but his brilliant first-innings performance was almost overshadowed by three incidents involving umpire Steve Davis.
South Africa trail by 199 runs having earlier in the day bowled Pakistan out for 338, Vernon Philander picking up five for 59.
The most heated debate occurred after Jacques Kallis was given out lbw for two off Ajmal by third umpire Billy Bowden.
Davis had lifted his finger for what seemed to be a catch off bat and pad and the unhappy Kallis decided to opt for a television review.
Hot-spot showed no edge but the replay revealed the ball would have gone on to clip the outside of leg stump and he was given out lbw.
Kallis argued that he should not be given out as the original bat-pad decision was wrong. However, after lengthy talks between Davis and Bowden, the South African had to walk back to the pavilion.
Ajmal bowled non-stop for 25 overs from just before tea to hand the initiative to Pakistan.
Captain Graeme Smith was his first victim, trapped lbw for 19 while attempting a sweep. Davis originally said it was not out but the visitors asked for a review and it showed the ball would have hit the stumps.
Azhar Ali then took an excellent one-handed catch at short leg to dismiss Alviro Petersen for 17, Ajmal finding an inside edge that deflected off the pads.
Hashim Amla (25) was then struck on the pads playing back to Ajmal. Once again Davis gave it not out but the lbw shout was overturned on review.
Faf du Plessis took more than two hours to make 28 before his long vigil was ended when he was caught at slip by Younus Khan off Ajmal.
AB de Villiers (24) and Dean Elgar (11) were the unbeaten batsmen when stumps were drawn.
Earlier, Philander registered his ninth five-wicket haul in Tests to bowl Pakistan out on the stroke of lunch.
Philander removed Asad Shafiq for 111 with his first ball of the day before claiming the scalps of Sarfraz Ahmed (13) and Umar Gul (0).
Tanvir Ahmed (44) and Ajmal (21 not out) put on 64 for the ninth wicket until the former fell to Robin Peterson.
Off-spinner Peterson also accounted for the final wicket of Mohammed Irfan (6).
South Africa lead the three-match series 1-0.
- Sports & Recreation
- Vernon Philander
- Steve Davis
- Jacques Kallis