A converted try in the first half from Hamish Watson had Scotland 7-3 ahead at the break but the Wallabies fought back despite a host of problems in their pack caused by injuries and a yellow card for prop Allan Alaalatoa.
The visitors twice led in the second period - they scored a try through Rob Leota when down to 14 men - but a wonder try from debutant Ewan Ashman and a penalty from Finn Russell saw Scotland squeeze home.
“We were disappointed and frustrated at half-time, even though we were ahead on the scoreboard,” said Townsend.
“The Australian try when they were a man down really shook us into gear, and I think there was a real edge about our play after that.
“We had to front up physically because there were a lot of scrums and a lot of mauls, and then we were still able to play with width at times which we had been aiming to do in the first half.
“I think just the character of the team as opposed to the performance today was the really pleasing thing. And the impact of all 23 as well. We found a way to win in the end.”
While Ashman grabbed the headlines, Townsend also singled out Josh Bayliss. The Bath flanker came off the bench and made a key turnover late on as Australia chased the game.
“I have to mention Josh Bayliss and his impact,” said the coach. “He got a really good turnover that reminded of one of Cam Redpath’s turnovers at Twickenham on his first cap. That was a massive moment.”
Townsend said Scotland would need to step up a gear for Saturday’s visit of the Springboks.
“They have a unique way of playing – it is very demanding physically so a huge effort will be required from the forwards at set-piece, and a huge effort will be required to deal with their kicking game,” he said.