Rassie Erasmus' much-improved Springboks led 20-17 after a thrilling first half which featured four tries.
Jesse Kriel and Handre Pollard both gave South Africa the lead with tries only to be cancelled out on both occasions by Peter Horne and Hamish Watson.
Asked if he regretted going for touch rather than taking a kick at goal, Greig Laidlaw said: "Potentially, yes, but you have got to be courageous to win Test matches".
Townsend praised South Africa for their defensive display as the Boks became only the second team in 12 attempts to win on Scottish soil following on from New Zealand's win a year ago.
But within two minutes Scotland paid the price for over-adventurous play with ball in hand in their own 22 as they were snagged and Springbok captain Siya Kolisi forced a turnover that set Pollard away for a try to make it 14-7.
Pollard's three penalties and Elton Jantjies' clinching kick ultimately proved the difference, and Townsend believed his side's display was deserving of a positive result.
A Pollard penalty made it 20-17 at half-time but Laidlaw ensured parity soon after the break when Willie le Roux was penalised and sin binned after a botched attempted interception was ruled a deliberate knock down.
The loss ends Scotland's undefeated streak at home at 2018. We had enough opportunities to put points on the board off the back of that.
"It was pretty frustrating but we couldn't generate any speed of ball in the second half", said Laidlaw.