Australia has survived an almighty scare from Scotland to secure a Sydney Cup quarter-final spot, with a 24-21 victory.
The Aussies led by 10 points at half-time but found themselves trailing with two minutes to go, until a Tom Lucas score propelled them ahead by three points.
Lucas was playing his first match of the tournament, replacing the injured Boyd Killingworth after Killingworth suffered a hamstring injury.
It was a score that proved invaluable in the match but also for Australia's fate in the tournament.
A loss would have knocked them out of the Cup part of the draw on points difference, with the USA beating Canada 40-19.
Aussie debutant Tom Connor, was left watching on after the final whistle, yellow-carded for tackling a man in the air, gifting Scotland the final possession of the game and sending plenty of panic through the Aussie camp.
A double knock-on ended Scotland's chances and the Aussies hung on, securing top spot in Pool D and a Cup quarter-final against New Zealand.
Coach Andy Friend was pleased with the heart his side showed, but admitted they needed to improve against the Cape Town champions.
"Our highs were very high," he said.
"I thought there was some really good rugby played but our lows, we were just ill-disciplined at the wrong times and made some really poor decisions defensively I thought, which tomorrow you come into quarter-final days and it's going to hurt you.
"We're three from three, we must be happy with that, we are happy with that but we're going to have to tidy up a few areas for tomorrow."
Scotland tried to burn the Aussies on the edge early but it was the hosts who managed the first score, with Jesse Parahi fending off a Scotsman to cross in the second minute.
Lachie Anderson had his first try of the weekend, blitzing the field down the left edge to score Australia's second.
They weren't able to hold out a Scotland score for long, with Jamie Farndale sprinting away in the fifth minute to narrow the margin back to five.
Persistence paid off for the Aussies in the dying seconds, with John Porch finishing off a multi-phase effort to stretch Australia's lead.
Scotland had the upper hand at the start of the second stanza with Scott Riddell collecting an offload to score with five minutes to go and a Max McFarland score two minutes later, put the Scots in front for the first time in the match, before Lucas scored the match winner.
Aussie skipper Lewis Holland said the message was simple in the final moments, with a man down.
"They're a very physical side, they're a good side and they're going to be hurting from that defeat too, so we know what we're going to come up against tomorrow," Friend said.
"Tomorrow if we can get the football we're going to make smart decisions and try and keep that ball off them."
Australia will play New Zealand in their Cup quarter-final on Sunday at 12:12pm AEDT.
Tries: Parahi, Anderson, Lucas
Cons: Stannard, Lucas
Yellow Cards: Connor (14')
Tries: Farndale, Riddell, McFarland
Cons: Fergusson 2, Lowe