South Africa closed to within 41 runs of victory in the second Test against Pakistan after a strong finish to a third day in which the tourist initially fought hard at Newlands.

Pakistan had offered precious little with the bat in its first three innings of the series – scoring under 200 on each occasion – and they still had work to do in the field as play began on Saturday, the Proteas on 382-6 and leading by 205.

Yet Mohammad Amir (4-88) took three early wickets as South Africa added just 49 runs and then Asad Shafiq made 88 and Shan Masood 61 for Pakistan.

But the dismissal of Masood late in the second session gave the Proteas a much-needed boost and they made light work of the rest of the Pakistan side, with Dale Steyn (4-85) and Kagiso Rabada (4-61) helping to limit the tourists to 294.

Pakistan's lead stood at just 40 runs, but Faf du Plessis' men ran out of time to get the job done and will now have to return on Sunday with what should be the simple task up wrapping up the three-match series. 

Amir made a flying start to the day as Quinton de Kock (59) edged to second slip before the stumps of both Vernon Philander (16) and Rabada (11) were uprooted in the same over.

Some late boundaries were then halted when Shaheen Shah Afridi (4-123) tempted Steyn (13) to pick out third man, capping the Proteas lead at 254.

Pakistan still looked to be in real trouble after another dismal start with the bat, falling to 27-2 after the dismissals of Imam-ul-Haq and Azhar Ali (both 6), but there was belatedly some good fortune for the tourists as two reviews went against Philander and the third-wicket stand reached 132.

But Steyn made a timely intervention shortly before tea as Masood nicked behind, then Shafiq edged Philander to De Kock following the restart and Rabada caught and bowled Fakhar Zaman (7).

Duanne Olivier collected the wicket of Sarfraz Ahmed (6) and Amir gloved Steyn behind for a duck, with a party atmosphere improved further as substitute fielder Zubayr Hamza caught Yasir Shah (5) at the rope.

Babar Azam's resolute knock ended on 72 to Rabada, but Philander's dismissal of Mohammad Abbas (10 not out) – with Pakistan just 24 runs in front – was ruled out for a no ball and, although he made amends as he caught Afridi (14) off Rabada, there was no time for South Africa to begin their reply.