They were leading 7-3, playing well. They hung on until Beale was yellow-carded for a deliberate knockdown and lost the lead to Wales' first of two tries.
But Wales, as they did against 14-man Fiji last weekend, couldn't fully exploit their one- or two-man advantages.
"Sometimes you need to win ugly and we'll take that," captain Ellis Jenkins said.
Valetini is an incredible sixth player to be red-carded against Wales this year, and the Welsh have used them to post four wins, a draw and a loss.
"Pressure creates cards and we're creating that pressure," coach Wayne Pivac said.
A team without eight injured British Lions made it hard on themselves to beat Australia, though.
The Welsh led 23-13 approaching the hour mark until they had one of their own sin-binned, replacement prop Gareth Thomas.
Australia, confident throughout, zipped in its second and third tries, and James O'Connor had a chance to regain the lead with a third conversion attempt, but his sideline shot hit the near post.
But Beale kicked them in front, followed by a breathtaking finish from Wales to beat the Wallabies three times in a row for the first time since 1975.
"Development has been forced on us and we've gone a bit deeper than wed have liked to," Pivac said of his injury-hit squad which has gone 2-2 this autumn.
"That's why it's so pleasing to get the win with the side that finished the game. If you'd have asked me if we'd have done that before the autumn, I'd have thought you were joking."
It all started brilliantly for Australia. Hunter Paisami and Taniela Tupou helped to set up an Andrew Kellaway converted try after just two minutes. Tupou even popped up Wyn Jones for a scrum penalty, but then Valetini was sent off.
"We lost our No. 8, that changes a lot of things," said James Slipper, the stand-in skipper for the injured Michael Hooper.
"We put ourselves in a position to win it at the end, they showed a lot of character to fight tooth and nail. I couldn't be more proud of the boys, but Wales were just good enough."
When Beale was sin-binned, the fifth card issued to the Wallabies in three matches, Wales pounced. Scrumhalf Tomos Williams shot the blindside from a lineout and gave hooker Ryan Elias his third try in two weekends.
O'Connor evened the score, then saw his forwards earn a seven-man scrum penalty in defense of their tryline.
But an offside infraction, Australia's ninth penalty of the half, was knocked over by Biggar to give them the halftime lead at 16-13.
There was more farce when Wales center Nick Tompkins knocked a Wallabies pass down, and everyone stopped, except Tompkins. He picked up and skipped away to the posts with referee Mike Adamson correctly saying he knocked the ball backwards, not forwards, which would have seen him sin-binned.
Wales led 23-13 then went down to 14 after Thomas swung at the head of opposite prop Allan Alaalatoa.
With 14 on 14, Beale stepped through the defense, and Len Ikitau sent Nic White tearing off to the posts. O'Connor converted to trail 23-20.
Biggar extended the lead to six after Paisami tackled off the ball, but Paisami made up for it by slicing open the Welsh, ending in Filipo Daugunu diving into the left corner in his first test since he broke his arm in July.
O'Connor hit the post for his first goalkick miss and departed, and Beale took the next goalkick for the lead, from a penalty won by Will Skelton.
But there was time for Wales to respond with its most fluid play of the night, and forcing the Australians to cough up their 13th penalty. Priestland kicked it straight and true.