LONDON - With the crowd booing, fuming Scotland players huddled within earshot, and with the Rugby World Cup ambitions of two countries balancing on his kick, Bernard Foley calmly landed a last-minute penalty goal that gave Australia a 35-34 win on Sunday.

Australia's win, decided on a contentious penalty for offside awarded by referee Craig Joubert in a dramatic climax to the quarterfinals, ensured the semifinalists are all from the southern hemisphere for the first time.

The Wallabies will play Argentina, which thumped Ireland 43-20 hours earlier at Cardiff.

Defending champion New Zealand faces South Africa — both teams have won the title twice.

Joubert's hasty departure from the field caused an outcry on social media, drawing harsh criticism not only from Scottish supporters but from former test players as well.

Few figured Scotland, which placed last in the Six Nations and narrowly held off Samoa to finish second in Pool B, had a chance against the Wallabies, who were the form team of the pool stage with wins over England and Wales. But the Scots were Europe's last hope in the tournament, and shook the Australians with their grit, their energetic ball carries and their physical presence at the breakdown.

The crowd of 77,110 was overwhelmingly backing the Scots, and it erupted when the Scots rallied to take a 34-32 lead five minutes from time when centre Mark Bennett intercepted a pass and sprinted 30 metres untouched to score between the posts, and his inspirational captain Greig Laidlaw, converted it.

Heading into the last minute, Scotland was penalized for offside as the loose ball bobbled around from a lineout, giving Foley the chance he needed to make amends for his three missed conversions in the first half. Despite the rain and the nerves, he nailed it.

"That's a penalty and that's how it works — that's life," Australia coach Michael Cheika said on the field, to another chorus of boos and howls. "You've still got to kick it."

Laidlaw, who kicked five penalties and two conversions to keep Scotland in the game as Australia piled on five tries, was on the verge of tears after the match.

"We're one kick away from being in the semifinals of the World Cup, and arguably we should have been," Laidlaw said. "It's hard to take. It's a very, very upset dressing room."

Laidlaw didn't think Jon Welsh was offside at the end, arguing that replacement Australia scrumhalf Nick Phipps touched the ball after it went forward off Scotland's Josh Strauss and was caught by Welsh.

He said he didn't even think Joubert was certain of it, and said, "He made a sharp exit at the end of the game, that's for sure."

The match concluded a disruptive week for Scotland that included two players being suspended for three weeks before having their bans overturned and being recalled on match day. Early in the second half, winger Sean Maitland was yellow-carded for a deliberate knock-on when he appeared to be reaching for an intercept, another call that Scotland coach Vern Cotter described as "50-50."

The Australians scored five tries, including a pair to veteran winger Drew Mitchell that took his career tally to 14 in the World Cup — one off the record — and others to Adam Ashley-Cooper, Michael Hooper and Tevita Kuridrani.

The three first-half tries weren't converted, and Scotland led 16-15 at the break despite scoring only one try — when Pete Horne strolled through some non-existent defending in a ruck. Both teams crossed twice in the second half as the lead changed three times, from Finn Russell's chargedown of Foley's attempted clearance kick, and from the late intercept that erased Australia's eight-point lead and nudged the Scots in front.

The Australians made too many uncharacteristic errors and the scrum that worked well in four previous games was hammered by the Scots and conceded penalties. Scotland, meanwhile, played the percentages well and converted their trips into the Wallabies' 40 into points.

Asked if it was the great escape, Cheika said with five tries in a quarterfinal "you expect to be somewhere near the winning end of a game."

"We went after it. We continued to go after it — maybe that's a bit naive from me. Maybe we shouldn't have opened it up for them," he said. "For where we are right now, if that's an escape, then I'm happy to escape."