A score from centre Garyn Smith and a penalty try, both converted by fly half Luke Price, had seen Wales pull well clear and when wing Josh Adams added a third, Wales looked to have victory in the bag.
Up till that point, Australia had shown very little with Andrew Deegan's missed penalty their only chance of points. But after going 19-0 down, they showed some fight when Wales' Jordan Viggars was yellow carded.
Captain Jack McCalman and fellow backrower Lolo Fakaosilea both touched down and with Deegan adding a conversion, Australia were back in it.
After such a good first half performance, defeat would have been inconceivable for Wales and on the stroke of the final whistle, Tyler Morgan made sure of the victory, crashing over under the posts for Wales' fourth try of the day.