Chasing a challenging 267-run target, Pakistan were bowled out for 238 in 49.2 overs with Dale Steyn taking a career best 5-25.
Misbah-ul Haq top-scored with 65 while debutant Sohaib Maqsood made 56.
For South Africa, opener Quniton de Kock hit a maiden hundred with 112 while Hashim Amla(46) and AB de Villiers (30) were other contributors.
The fifth and final match is in Sharjah on Monday.
Complete scoreboard:
South Africa:
Q. de Kock c Misbah b Khan 112
Hashim Amla b Hafeez 46
F du Plessis c Ajmal b Irfan 10
AB. de Villiers c Hafeez b Khan 30
D. Miller lbw b Hafeez 5
JP Duminy not out 25
R. McLaren not out 28
Extras: (b1, lb9) 10
Total: (five wickets; 50 overs) 266
Fall of wickets 1-87 (Amla), 2-129 (du Plessis), 3-198 (De Villiers), 4-210 (De Kock), 5-214 (Miller)
Bowling: Irfan 8-0-51-1, Tanvir 6-0-38-0, Khan 9-0-42-2, Ajmal 10-0-53-0, Afridi 8-0-38-0, Hafeez 9-0-34-2
Pakistan:
Ahmed Shehzad run out 43
Mohammad Hafeez b Tahir 33
Sohaib Maqsood c de Villiers b Steyn 56
Asad Shafiq c Morkel b Tsotsobe 1
Misbah-ul-Haq c de Villiers b Steyn 65
Sohail Tanvir c Amla b Steyn 1
Umar Akmal c Morkel b Steyn 22
Shahid Afridi run out 3
Saeed Ajmal b Steyn 0
Mohammad Irfan not out 2
Junaid Khan b McLaren 4
Extras: (lb1, w7) 8
Total: (all out; 49.2 overs) 238
Fall of wickets 1-74 (Shehzad), 2-85 (Hafeez), 3-86 (Shafiq), 4-174 (Maqsood), 5-180 (Tanvir), 6-228 (Umar), 7-230 (Misbah), 8-231 (Ajmal), 9-232 (Afridi)
Bowling: Steyn 10-1-25-5 (w2), Tsotsobe 10-0-49-1 (w2), Morkel 10-0-44-0, McLaren 9.2-0-59-1 (w3), Tahir 8-0-51-1, Duminy 2-0-9-0
Result: South Africa won by 28 runs
Toss: South Africa
Umpires: Ahsan Raza (PAK) and Steve Davis (AUS)
TV umpire: Richard Illingworth (ENG)
Match referee: Ranjan Madugalle (SRI)