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.
"It was just about making our one-on-one tackles, they had a long way to go to the try line because they set that scrum, so it was just about staying on our feet.
"When we needed to tackle, we tackled, but (we just said) just get back to your feet and reload, put the pressure on them in our defensive structures and get in off the line and let them make the error rather than us trying to solve the problem."
Both Friend and Holland were happy with the grit the side showed, something that will be crucial as they prepare for a New Zealand side smarting from a heartbreaking loss to Fiji on Saturday afternoon.
"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."
The Aussies will be sweating on the fitness of livewire Maurice Longbottom, who rolled his ankle after Australia's pool game against Canada, with Friend unsure whether he will be fully fit to play on Sunday.
Australia will play New Zealand in their Cup quarter-final on Sunday at 12:12pm AEDT.
Keep up with all the day two action here.
RESULT
Australia 24
Tries: Parahi, Anderson, Lucas
Cons: Stannard, Lucas
Yellow Cards: Connor (14')
Scotland 21
Tries: Farndale, Riddell, McFarland
Cons: Fergusson 2, Lowe