Australia secured a last-minute 14-12 win over Wales to send retiring captain Nathan Sharpe out a winner in his final Test.