Ali hit a patient 134-ball 45, laced with six boundaries and Misbah struck 81-ball 36 as Pakistan recovered from 3-45 to reach 100-3 at stumps, extending the overall lead to 112.
Earlier, riding on Robin Petersen’s career-best 84, South Africa managed to score 326 runs in reply of Pakistan’s 338.
Reducing Pakistan’s deficit margin to just 12 runs, South African pace attack began with and blew away the tourists openers inside nine balls to leave them 2-7.
Pace spearhead Dale Steyn dealt Pakistan first blow by trapping Mohammad Hafeez in front of stumps of wicktets on the second ball of the innings before Philander scalped Nasir Jamshed in the similar fashion in the next over.
The stay of first-innings centurion Younis Khan on crease wasn’t long this time as he was bowled off Steyn after scoring just 14 runs.
Ali and Misbah launched a strong recovery and started rebuilding the innings with sagacious stroke-play.
Late in the day, Ali survived a caught behind appeal off Philander’s delivery despite TV replays suggesting the ball had nicked the bat before being secured to the hands of gloveman AB de Villiers.
Earlier, despite of reducing the hosts to 139-5 overnight, Pakistan failed to prevent the hosts from reaching close to their first-innings total.
Peterson hit his career-best 84, sharing a 46-run seventh-wicket stand with AB de Villiers (61) and 49-run eighth-wicket stand with Philander (22), before eventually been perishing off spinner Hafeez.
Petersen’s whirlwind 106-ball vigil was laced with 15 boundaries.
Off-spinner Saeed Ajmal was the pick of Pakistani bowling with the figures of 6-96, lanky pacer Mohammad Irfan finished with 3-86.
South Africa are leading the three-Test series 1-0 after winning the first Test in Johannesburg by 211 runs.