As it happened: Pakistan v Proteas
The off-spinner (4-74) was superbly supported by left-arm paceman Junaid Khan (3-57) and fellow spinner Zulfiqar Babar (2-51) as South Africa collapsed to 232 in their second innings on the fourth day at Sheikh Zayed Stadium.
That left Pakistan to score 40 runs for their overall fourth win over South Africa and take a 1-0 lead in the two-match series.
Pakistan made heavy weather of the small target losing openers Shan Masood (nought), Azhar Ali (three) and Khurram Manzoor (four) in the space of seven runs by the fourth over.
Vernon Philander took 2-11 while Dale Steyn had 1-7.
Senior batsmen Younis Khan (28) and Misbah-ul Haq (nine) were left to see off the target with Pakistan captain deservedly hitting the winning six.
It was AB de Villiers who hit a fighting 90 to help South Africa avoid an innings defeat while Robin Peterson scored a valiant 47 not out but it only delayed Pakistan's win.
This is Pakistan's fourth win over South Africa in 22 Tests and also broke South Africa's 15 Tests unbeaten run since losing to Sri Lanka at Durban in December 2011.
De Villiers added an invaluable 57 for the eighth wicket with Petersen to carry the match into the final session.
Peterson added an invaluable 42 for the ninth wicket with Vernon Philander (ten), much to the frustration of the Pakistani bowlers.
De Villiers hit seven boundaries and a six off 157-ball in a resistance filled innings before he miscued a drive off paceman Junaid Khan with just three to avoid an innings defeat.
Pakistan's bowlers had grabbed two wickets in the morning session to boost their chances on a pitch offering good turn after South Africa resumed at 72-4, trailing by a big 121 runs.
Left-arm spinner Babar dismissed nightwatchman Steyn (seven) and then paceman Jinaid Khan removed Jean-Paul Duminy (nought) as South Africa struggled against a spirited bowling attack.
Steyn had frustrated Pakistan in the first hour, playing defensively till the 12th over of the day when Babar was introduced into the attack and with his first delivery bowled the nightwatchman.
Duminy, who hit 57 in South Africa's first innings of 249, survived just five deliveries before he was trapped leg-before by Khan, leaving South Africa tottering at 109-6.
Pakistan removed Faf du Plessis soon after lunch when Ajmal had him caught and bowled for eight.
De Villiers brought up his 33rd Test half-century with a big six off Babar. In all he hit seven boundaries and a six off 157 balls.
He hit a straight drive into the hands of cover off Khan, with just three needed to avoid an innings defeat.
Peterson and Philander (ten) further delayed the inevitable but Ajmal removed Philander and Morne Morkel in the same over to wrap up the innings.
The second and final Test will be played in Dubai from October 23.