Hashim Amla hit his third Test double century and Stiaan van Zyl made a hundred on his debut before South Africa declared their first innings at 552/5.
South African Stiaan van Zyl waited a long time for his Test debut but made the most of the opportunity when it finally arrived with an unbeaten century.
With nothing separating the two teams in the preceding Test and T20I series, Pakistan and New Zealand will aim to leave the UAE on a high with a series win.
Pakistan coach Waqar Younis feels a win in the fifth and final one-dayer against New Zealand in Abu Dhabi on Friday will give his team a boost for next year's World Cup.