After resuming on the third morning on 139 for five in response to the tourists' 338, the Proteas were bowled out midway through the afternoon session for 326, a deficit of just 12.
Peterson was last out for 84, with AB de Villiers earlier making 61 before becoming Mohammad Irfan's first Test victim.
That ended Ajmal's chances of taking all 10 wickets.
The spinner picked up the first five yesterday and added his sixth this morning when he ended a stand of 55 between De Villiers and Dean Elgar (23), the latter edging a loose drive straight to Younus Khan at slip.
Irfan ended up with three for 86 on his debut, while Ajmal took six for 96.