South Africa defeated India by four wickets in a high-scoring second ODI to level the three-match series 1-1 in Raipur.