Australia celebrated George Gregan's 100th Test with a pulsating Tri-Nations victory over South Africa in Perth.
Australia 30 (15)
Tries: Tuqiri, Larkham, Latham, Rathbone
Cons: Giteau, Burke
Pens: Giteau 2
South Africa 26 (16)
Tries: V d Westhuizen, De Villiers, Du Toit
Pens: Montgomery 3
The Wallabies were forced to come from behind on several occasions as the lead changed hands seven times in all.
The home side edged the try count four-to-three, with former Springboks U-21 captain Clyde Rathbone crossing for the winning score nine minutes from time.
A second successive agonising defeat dented South Africa's Tri-Nations hopes, but the Wallabies' remain alive.
The result was harsh on South Africa, who were unfortunate to lose in the last minute to New Zealand a week ago, and who again showed how much they have progressed.
But the Wallabies, who trailed 16-7 in the first half and 26-23 inside the final quarter, rallied impressively ahead of next week's return clash with the All Blacks.
The Springboks showed a willingness to run the ball at their more vaunted opponents, an early Breyton Paulse break yielding a penalty for Percy Montgomery.
But the Wallabies opened the try-scoring when Lote Tuqiri beat Montgomery to a high kick from Matt Giteau to force his way over after six minutes, Giteau converting for a 7-3 lead.
Tuqiri grabbed Australia's opener
The Springboks refused to be cowed and responded with Paulse releasing de Villiers, the wing kicking ahead for Van der Westhuyzen to touch down.
Another Montgomery penalty put the visitors 11-7 up by the end of the first quarter, and they went further ahead after 22 minutes.
Stephen Larkham's pass on the South African 22 was intercepted by the flying De Villiers, who sprinted 80m to cross for the Boks' second try.
Australia, frustrated in the opening half-hour, rallied in the final 10 minutes of the first half to reduce the deficit to a point.
After a sweeping counter-attack yielded a line-out close to the South African line, Larkham swept past the onrushing Van der Westhuyzen and held off the remaining cover to force his way over.
Giteau missed the conversion from almost in front of the posts, but he made no mistake with a simple penalty to leave Australia only 16-15 down at the interval.
Another Giteau penalty on the resumption edged the Wallabies back in front, only for Montgomery to land his third to regain the lead at 19-18 after 50 minutes.
Australia appeared to have made the decisive move when Larkham's brilliance conjured a try for Chris Latham in the left corner before the hour.
Du Toit's try regained the lead
But South Africa hit back again when a perfectly judged kick from De Wet Barry was collected by replacement Gaffie du Toit to dive over.
Montgomery's conversion made it 26-23 in the Boks' favour, but Tuqiri and the outstanding Larkham combined to send Rathbone over at the right corner.
Matt Burke, on as a replacement, landed the conversion and despite a desperate last-ditch bid for victory, the Springboks were denied once again.
Australia: C Latham, C Rathbone, S Mortlock, M
Giteau, L Tuqiri, S Larkham, G Gregan (capt); B Young, J Paul, A Baxter, J Harrison, N
Sharpe, G Smith, P Waugh, D Lyons.
Replacements: A Freier, M Dunning, D Vickerman, J Roe, C Whitaker, M Burke, W Sailor.
South Africa: P Montgomery, B Paulse, M Joubert, D W Barry, J de Villiers; J van der Westhuizen, F du Preez; O du Randt, J Smit (captain), E Andrews, B Botha, G Britz, S Burger, AJ Venter, J Cronje.
Replacements: H Shimange, CJ van der Linde, A van den Berg, J van Niekerk, B Conradie, G du Toit, B Russell
Referee: C White (England)