Bhatti and Ali shared an eighth-wicket stand of 74 to rescue Pakistan from a precarious 131 for 7, and then shared five wickets as Pakistan won by 23 runs.
Pakistan made 218 for 9 in their 50 overs after winning the toss. Despite a half-century from returning veteran Jacques Kallis, South Africa was bowled out for 195.
Bhatti (39) and Ali (43 not out) prospered after Pakistan's recognised batsmen struggled against a strong South African pace attack.
With Jacques Kallis returning for his first ODI since February 2012, South Africa applied relentless pressure as Pakistan struggled. But Bhatti and Ali went for their shots to keep their side in the game.Steyn took 3 for 33 and Morkel 3 for 39, while Philander claimed one for 37.
Nasir Jamshed and Ahmed Shehzad put on 49 for the first wicket, but Steyn dismissed Jamshed in the 16th over and followed up with the wicket of Mohammad Hafeez, both caught in the slips.
Pakistan's leading batsmen were unable to build any substantial partnerships and could not lift the scoring rate. They looked to be headed for a low total when Shahid Afridi was bowled by Steyn in the first over of the batting power play.
But Bhatti and Ali put on 74 off 70 balls. Bhatti made 39 off 25 balls, hitting three fours and two sixes, while Ali hit six fours in a 55-ball 43 not out.
South Africa suffered an early blow when Hashim Amla exposed his leg stump and was bowled by Junaid Khan in the third over of their innings. Graeme Smith followed in the next over, stumped by Umar Akmal off Mohammad Hafeez, although it was a fortuitous dismissal for the wicketkeeper as the ball bounced off his gloves, on to the ground and then the stumps while Smith's foot was momentarily off the ground.
Kallis and Quinton de Kock put on 42 for the third wicket before De Kock was bowled by Bhatti.
Batting with calm assurance, Kallis reached brought up his 103rd ODI half-century but was then bowled by Ali, edging an inswinging delivery off the bottom of his bat on to the stumps. When David Miller edged Ali to Akmal, South Africa was 123 for 6.
JP Duminy made 49 before he was caught behind, attempting a reverse sweep against Saeed Ajmal, and Bhatti claimed the last two wickets to seal a memorable win for Pakistan, who was beaten 4-1 by the same opponents in a recent series in the United Arab Emirates.
Bhatti finished with 3 for 37, while Ali took 2 for 24.