Amla scored a memorable 196, while de Villiers made magnificent 169 as South Africa made a mammoth 569 in their second innings. Australia 40 for 0 at stumps on day three.
Perth: Hashim Amla and AB de Villiers posted big centuries in quick time before South Africa was dismissed for 569 late on Sunday, setting Australia an unlikely victory target of 632 in the third Test.
David Warner (29) and Ed Cowan (9) survived an hour before stumps to steer the Australians to 40 without loss on day three, cutting the target to 592 with two full days remaining in a Test that will decide the No. 1 ranking for 2012. After 20 wickets tumbled in the first five sessions, the top-ranked South Africa seized control in the second innings with Amla scoring 196 and de Villiers contributing 169.
Amla batted for almost six hours and stroked 20 boundaries as he shared stands of 178 with Graeme Smith (84), 81 with Jacques Kallis (37) and 149 with de Villiers until he gave a return catch to Mitchell Johnson in the middle session.
De Villiers continued, reaching his 14th Test hundred with three consecutive reverse sweeps for boundaries from offspinner Nathan Lyon and belting 21 boundaries and three sixes before he was eventually caught behind off Mitch Starc for 169.
After pounding the Australian bowlers for three sessions, the South Africans lost their last five wickets for 31 runs with left-arm pacemen Starc (6 for 154) and Johnson (4 for 110) taking all the wickets.
The record successful fourth-innings chase is West Indies' 418 for 7 to beat Australia at St. John's in 2003. The South Africans went close to that here four years ago when they scored 414 for 4 to beat Australia and clinch the 2008 series.
The highest fourth-innings total was England's 654 for 5, from 218 eight-ball overs, chasing 696 to beat South Africa in a famous timeless match at Durban in March, 1939, when both captains finally agreed to a draw after 10 days of play so the tourists could get a ship back to Britain.
The South Africans only need a draw at the WACA to retain the No. 1 Test ranking, while Australia needs a victory to replace them in top spot.
Amla resumed on 99 with South Africa at 230 for 2 on day three and reached his 18th Test hundred in the first over. He treated the inexperienced bowling attack almost with disdain at times by walking across his off stump and flicking the ball onto the legside, scoring with ease for most of his 221-ball knock. He dominated the partnership with Kallis, who top-edged an attempted hook off Starc and was caught by Johnson to give Australia its only wicket of the morning session.
The Australian attack, missing all three pacemen who played in the first two drawn Tests, had only picked up one wicket in 3 1/2 hours before Johnson's double breakthrough in one over to remove Amla and Dean Elgar as the South African slipped from 3 for 436 to 5 for 436.
Johnson took his second caught-and-bowled dismissal of the innings, this time with a reflex, right-handed grab to dismiss Amla on the first ball of the 89th over. Then, after hitting Elgar on the elbow and shoulder with some short-pitch balls, he trapped the rookie South African lbw to give him a pair of ducks on debut.
The South Africans added 69 runs in the six overs after the tea interval, with de Villiers and Faf du Plessis (27) flaying the bowling attack to all parts of the ground.
Du Plessis had been a thorn in Australia's side since making his debut in Adelaide, where he batted through the last day to salvage a draw for South Africa.
He shared a 102-run partnership with de Villiers on Sunday before his defiance of the Australian bowlers ended, edging Johnson to Michael Clarke at slip. He scored 215 between dismissals in the series. Starc then dismissed the last three tailenders as South Africa deciding not to declare.