LONDON (REUTERS) - A controversial last-gasp penalty by Bernard Foley earned Australia a 35-34 victory at Twickenham on Sunday that broke Scottish hearts and sent the Wallabies into a World Cup semi-final against Argentina.
Scotland had been on the verge of a stunning upset with 79 minutes on the clock but South African referee Craig Joubert awarded Australia a penalty for offside, despite the ball appearing to come off a Wallaby shirt.
Amid a cacophony of boos, flyhalf Foley kept his composure to split the posts and ensure the World Cup would have four southern hemisphere semi-finalists for the first time.
New Zealand and South Africa will meet in the other semi-final, both games back at Twickenham next weekend.
The battle between the winners of the Rugby Championship and the side who finished last in the Six Nations after losing every game looked a mismatch on paper but there was nothing between them in what developed into an epic see-saw battle.
Australia were totally dominant for the first 10 minutes and were rewarded when a surging run by centre Tevita Kuridrani set up winger Adam Ashley-Cooper to score the opening try.
It looked ominous for Scotland but they roared back into the game, earning a Greig Laidlaw penalty then going ahead when Peter Horne picked the ball up at a ruck 10 metres out and, with the Wallaby defence momentarily frozen, strolled over the line.
With their tails up, Scotland tore into their highly favoured opponents and scored another penalty but Australia then turned to their forwards for a 10-phase assault that opened the door for Drew Mitchell to get their second try.
Australia's scrum, highly praised for how it dealt with England, found the Scottish version a tougher proposition and Laidlaw landed another penalty after a collapse.
Again Australia hit back, opting for a lineout instead of a shot at goal and validating the decision by driving flanker Michael Hooper over.
Foley, so deadly from the tee earlier in the tournament, missed all three conversions to allow Scotland to change round with an unlikely 16-15 lead.
The Wallabies had never won a World Cup match having trailed at the break but it took them only three minutes to regain the lead after Scotland wing Sean Maitland was yellow carded for a deliberate knock-on.
Australia again kicked for touch, mauled forward and sent Mitchell straight through the hole where Maitland should have been.
Five minutes later they repeated the trick on the other wing, Ashley-Cooper crossing, only for the TMO to chalk it off for a knock on.
Scotland continued to show real adventure with the ball and got back to within a point when Finn Russell charged down a Foley kick then kept his wits about him when he was tackled, popping the ball up for Tommy Seymour to score.
Again Australia hit back as Kuridrani forced his way over for their fifth try and, with Foley's conversion, the lead was opened to 32-24.
Another Laidlaw penalty, and an unexpected downpour, gave Scotland new hope going into the final 10 minutes.
That turned into a deafening roar when Mark Bennett intercepted a James Slipper pass to level, with Laidlaw's conversion putting the Scots two points ahead and dreaming of their first semi-final since 1991.
Australia, however, as they so often do, mustered one more attack and, despite Scottish pleas to the referee to go to the Television Match Official, took full advantage of their last-gasp escape route to stay in the hunt for a third World Cup.