Australia would need to better the record for a successful fourth-innings chase by 213 runs to win the match and clinch the series or bat for two more days to force a draw.
The hosts had eaten into their target to the tune of 40 runs without loss by the close of play with openers David Warner (29) and Ed Cowan (nine) having survived a sometimes nervous last hour.
After the first two Tests in Brisbane and Adelaide ended in draws, South Africa only needed a third in Ricky Ponting's last test to ensure they remained the world's number one side.
They will now expect to do considerably better than that and become the first team since the West Indies in the 1980s and early 1990s to win consecutive series in Australia.
Amla's brilliant innings was one for the purists, while de Villiers started slowly before accelerating after he reached his fifty to bludgeon the Australian bowlers with every shot in the book.
Picking up where he left off on Saturday when he helped the tourists plunder 206 runs in the extended third session, Amla got the single he needed to reach his 18th Test century from the third delivery of the day.
Peppering his innings with some sublime cover drives for a good few of his 21 boundaries, Amla's comfort at the crease had echoes of his unbeaten 311 against England at the Oval in July.
Australia's pace unit, acclaimed after ending South Africa's first innings for 225, toiled in the sunshine looking for a breakthrough but their best efforts only slowed the flow of runs.
It took a brilliant catch from Mitchell Johnson off his own bowling to dislodge Amla shortly before tea as the 29-year-old was approaching a double century after 350 minutes and 221 balls.
Johnson (4-110) found a little bit of extra pep with the new kookaburra and when the South African drove the ball back at him, he snatched it out of the air for a second superb caught and bowled of the innings.
Dean Elgar was despatched lbw by Johnson four balls later for a pair of ducks on his debut but the day already belonged to South Africa's batsmen.
De Villiers had moved reasonably cautiously to his 50, with the exception of one huge six off spinner Nathan Lyon that hit the second deck of the stand at long on.
He upped the pace with a string of quickfire boundaries to reach 89, then graduated to his 14th test century in stunning style with three successive reverse sweeps for four, again off Lyon.
Faf du Plessis (27) and Robbie Peterson, who failed to score, came and went before Johnson's fellow left-armer Mitchell Starc (6-154) finally removed de Villiers caught behind.
The 28-year-old was clearly furious with himself for having fallen short of the double century after his innings of 169 off 184 balls with 21 fours and a trio of sixes.
Ponting had earlier bowled one last Test match over at the cost of three runs to huge applause from the 13,000 crowd at the WACA, but the chance of finishing his career with a victory was surely gone.
The 418 scored by West Indies against Australia in 2003 was the highest successful fourth innings run chase in Test cricket, while South Africa scored 414 to win the corresponding test at the WACA four years ago.