The Blitzboks overturned the deficit after Tristan Leyds raced down the sideline and offloaded to Davids to score.
Australia captain Nick Malouf was red carded for a reckless high tackle, making direct contact to the head and South Africa punished the Aussies with loose handling pounced on by the potent Davids.
Brumbies flyer Corey Toole pulled one back for the Australians with a wonderfully weighted kick in behind to scoop up and score.
Henry Patterson scored the equaliser by bulldozing through to complete Australia's comeback from 19-7 down to draw level at 19-19 but a missed conversion and South Africa's extra man proved costly.
South Africa won possession back from the restart and Selvyn Davids' made an emphatic break down the left. He passed the ball inside to Williams, who touched down and denied Australia a shot at extra time and the bronze medal.
Earlier in the day, New Zealand claimed fifth place by beating Ireland 17-7 through scores by Leroy Carter, Brady Rush and Moses Leo.
Argentina finished seventh by beating the USA 19-0 as American flyer Perry Baker was yellow carded and Los Pumas made their numerical advantage count with two scores by Matias Osadczuk and a further try by Rodrigo Isgro.
Kenya beat Samoa 10-5 in the ninth place final through John Okoth's two tries, while Uruguay saw off Japan 21-10 to finish 11th courtesy of Juan Gonzalez's double and Mateo Vinals' touchdown.