Scotland looked ready to close out a deserved win but, just as in last year's Rugby World Cup meeting, the Australians grabbed victory in the dying minutes of an entertaining contest.
Centre Huw Jones scored two first-half tries and Jonny Gray's score made it 22-13 to the Scots after 48 minutes.
However, a Bernard Foley penalty closed the gap to six points and Tevita Kuridrani's 76th-minute try, converted by Foley, proved decisive.
Departing head coach Vern Cotter was frustrated with referee John Lacey's display but with seven games left before his Scotland reign ends next summer, the Kiwi was remaining positive.
He said: "We always come back to the old saying of fine margins. I wouldn't necessarily say the best team won.
"I'm incredibly proud of the players and the way they played that game.
"There are things we can control and things we can't, so we focus on the things we can.
"The players played with immense courage and threw themselves at it. I think we didn't get the rub of the green at times.
"There were eight penalties against us in the second half but only two for us. But as I say that is something we can't focus on.
"The most important thing for us is to get back to improving performances. That's what we will do."