Pakistan cricket team
Pakistan's Azhar, Fawad stand firm against South Africa
Alam, playing his first Test at home, was unbeaten on 39 and Azhar was on 38 as Pakistan added 71 runs without losing any wickets in the morning session.
The visitors looked set earlier before Pakistan spinners Yasir Shah (3-54) and Nauman Ali (2-38) weaved their magic.
Elgar and du Plessis have so far added 31 for the third wicket after Aiden Markram (13) and Rassie van der Dussen (17) fell, leaving the tourists wobbling at 63-2.
South Africa entered the Test - their first in Pakistan in 14 years - with two spinners, Keshav Maharaj and George Linde, to exploit a bare pitch which is expected to take spin.
De Kock is leading a 21-strong squad on South Africa's first tour to Pakistan in 14 years, where they will play two Tests and three Twenty20 internationals.
The win tentatively put New Zealand top of the World rankings and kept alive their chances of making the World Test Championship final.
New Zealand declared their second innings at 180 for five and Pakistan, set an unlikely target of 373, will go into the final day at 71 for three.
Faheem Ashraf soldiered on to a career-best 91 before he was the last wicket to fall.
India and Australia head New Zealand on the Test championship ladder, but if India continue to struggle and New Zealand sweep the series against an under-strength Pakistan, it could be enough to see the Black Caps at Lord's for the final in June.
Pakistan reached New Zealand's target with two balls to spare, ending on 177 after Iftikhar Ahmed sealed the win with a six in the final over.
Khan has won the toss in the previous two matches of the series, with Pakistan suffering heavy defeats both times.
International cricket found a way through this year's coronavirus pandemic but the strain of 'bubble life' was evident by the end of 2020.
Cricket South Africa announced on Wednesday that the decision had been made following a visit to Pakistan by a security delegation recently.
England will play two Twenty20 internationals in Karachi on 14 and 15 October 14 - the first time they have played on Pakistan soil since 2005.
Pakistan, who saw veteran Mohammad Hafeez (86 not out) and teenage debutant Haider Ali (54) share a partnership of exactly 100, won a last-ball thriller by five runs to square a three-match series at 1-1, with one no result, in the final fixture of their tour of England.
The tourists reached 187 for four in their second innings at the close, batting for 27.1 overs on the short final day, still 123 runs short of England’s massive 583 for eight declared.
Pakistan, following on, were 100-2 - still 210 runs behind England's first innings 583-8 declared - at the close.
Crawley's commanding 171 not out was the centrepiece of England's 332-4 at stumps after captain Joe Root won the toss.
England had made 110-4 declared in reply to Pakistan's first innings 236 when a draw was agreed in a match repeatedly interrupted by bad weather.