Salman Ali Agha and Mohammad Rizwan scored twin centuries as Pakistan beat South Africa by six wickets to book their berth in the final of the ODI tri-series against New Zealand.