Pakistan beat South Africa by six wickets