The game did not carry full one-day international status as the teams used their full 15-man squads.
Sent into bat, South African managed just 202 for nine in their 50 overs and Pakistan cruised to their target with six wickets and 27 balls to spare.
Ali claimed three for 30 in his 10 overs as he produced prodigious movement through the air early in the South African innings, figures matched by Riaz who bowled an over less.
"It is pretty satisfying, the way Wahab Riaz bowled was the biggest plus for us, but everybody in the top order also scored runs, so we are pretty happy about that," Pakistan captain Misbah-ul-Haq said.
Ryan McLaren (55) and JP Duminy (43) were the only South African batsmen to find form as they battled against the moving ball.
Pakistan never looked in trouble in their reply, with opener Imran Farhat (56) and Mohammad Hafeez (54 retired out) laying the platform for victory.
"It wasn't easy this morning, but I think we got out of it what we wanted. The boys toiled hard and were under pressure. We got over 200, which is a good effort in the end. All the bowlers then got a good run, which was important," Proteas captain AB de Villiers said.
South Africa begin their Champions Trophy Group B campaign against India in Cardiff on Thursday. Pakistan meet the West Indies in the same pool at The Oval on Friday.