Unpredictable win: Pakistan beat South Africa