South Africa were struggling at 139 for five at the close, still 199 runs behind Pakistan's first innings of 338. Ajmal took five for 41.
Three of Ajmal's wickets came after the use of the decision review system, including a controversial dismissal of star South African batsman Jacques Kallis.
South African captain Graeme Smith and Hashim Amla were both out leg before wicket after being given not out by umpire Steve Davis.
Kallis was given out caught at short leg and immediately called for a review, which showed that the ball had not touched his bat before looping off his pad to the fielder.
But he was then given out leg before on the advice of television umpire Billy Bowden, although replays showed the ball was only brushing the outside of his leg stump, in the area known as "umpire's call".
Kallis was clearly shocked and stood at the wicket seeking clarity before reluctantly returning to the pavilion.
It was not clear what the conversation between Davis and Bowden had been and on what basis Kallis was given out on what was a marginal call.
Controversy apart, it was a superb display of bowling by Ajmal, who bowled 25 overs unchanged into a stiff south-easterly wind, varying his flight and mixing off-spin with cleverly disguised top spinners and "doosras" which turned away from the right-handed batsmen.
It was a productive day for Ajmal, who helped fellow tailender Tanvir Ahmed put on 64 for the ninth wicket to take Pakistan comfortably past the 300 mark. Their eventual total seemed unlikely when Vernon Philander took three wickets in his first three overs to reduce the tourists to 268 for eight.
Ajmal came on to bowl after 11 overs had been bowled in South Africa's innings and struck with his ninth delivery, Smith missed a sweep and Pakistan successfully sought a review.
Two overs later Ajmal had Alviro Petersen smartly caught at short leg by Azhar Ali, who dived to his right to hold a sharp chance.
At tea, Ajmal had taken two for 20.
Amla went back on his stumps and was also given out on review before Kallis was dismissed.
He was followed by Faf du Plessis, caught at slip off a "doosra" for South Africa's highest score of 28.
AB de Villiers and Dean Elgar survived until the close.
Pakistan batted until lunch after resuming at 253 for five, although Philander's early strikes raised the home side's hopes of wrapping up the innings quickly.
Philander, who took five for 59, struck with his first ball of the day when Asad Shafiq was caught at first slip without adding to his overnight score of 111.
Shafiq batted for 308 minutes and faced 230 balls.
Sarfraz Ahmed, the other overnight batsman, fell for 13 in Philander's next over when Petersen dived full length to his right to hold a good catch at third slip.
Umar Gul was leg before wicket without scoring as Philander completed his ninth five-wicket haul in Test matches.
But Tanvir and Ajmal went for their strokes, with Tanvir in particular hitting out aggressively as he made 44 off 59 balls with four fours, while Ajmal made 21 not out.
South Africa suffered a blow when fast bowler Morne Morkel left the field after bowling three balls of his 21st over with what was described as a tight left hamstring.
Tanvir fell shortly before lunch when he hit left-arm spinner Robin Peterson to Philander at deep mid-off, with last man Mohammad Irfan following in the next over when he was bowled by Peterson, going for a big hit.
COMMENTS (9)
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ
@Antanu g You are right. Indians can never talk positive about Pakistan. Ur comment speaks sick Indian mindset in genral and ur stupid mindset in special. I have lived in UK with indians and ur comment strengthens my belief that Indians are worst people to talk or interact with.
Pakistan needs to restrict S.A before it crosses 250 to take full control over the match. Pak is in driving seat in this match, if they lose from here; it will be more like clinching loss from the jaws of winning.
after dismal play in first test, may be nobody was willing to bet on Pakistani team so they played as usual
Missing rehman, would been great if rehman and ajmal bowling in tantum. In the foutth innings batting won't be easy, anything around 220 will be challenging for proteas.
@Diggvijay Singh: Indeed Singh bhai. Pakistan Team have a knack for making comebacks in the oddest circumstances. :-)
I was expecting more efforts from other bowlers as well,.but in the end of well hats off to saeed ajmal
@antanu g:
I'm Indian and Team India is my favorite. I like the Pakistani team's mercurial style of game. They are very talented in the bowling department.
Ajmal has weaved his magic already and SA are 5 wickets down. Pakistan has a stranglehold on this match. SA will be fold for 180-200 runs and they have to face Ajmal on fourth or fifth day's viciously turning track. Team Green going for the kill.
@Diggvijay Singh: you are not indian sir...why this fake identity?
This is turning out to be a memorable Test match. Pakistan's bowling is its main strength. With their variations, if the Pak bowlers can restrict SA to 240 Pakistan will have a big chance of clinching this one. And that would be history because SA is the best Test team around. Our young guns Kohli and Pujara should check out Younus Khan's mature batting display. How he smothered the pace attack and picked on the right bowlers to score his runs. Very tactical and fascinating.