Australia survive scare to beat South Africa in low-scoring clash