The South African official sprinted off the field to boos and jeers from Scottish supporters at Twickenham after he blew the final whistle.
But Australia celebrated setting up a semi-final against Argentina — who thrashed Ireland 43-20. New Zealand will play South African in the other semi-final next weekend after they beat France and Wales, respectively, on Saturday.
With Scotland leading Australia 34-32 amid a rainstorm, Joubert hit trouble by ruling that Scottish replacement prop Jon Welsh had strayed offside. Australia scrum-half Nick Phipps appeared to touch the ball before Welsh was left in an offside position.
Wallaby fly-half Foley expertly scored the winning points.
Phipps later said he had deliberately attempted to win the loose ball which ought to have stopped a penalty from being awarded.
Scotland rugby great Gavin Hastings — commentating on the match for television — led criticism of the referee.
“If I see referee Craig Joubert again, I am going to tell him how disgusted I am. It was disgraceful that he ran straight off the pitch at the end like that,” Hastings said.
Former England scrum-half Matt Dawson, a World Cup-winner in 2003, said on Twitter: “Craig Joubert you are a disgrace and should never referee again!! How dare you sprint off the pitch after that decision!!!”
Scotland captain Greig Laidlaw questioned afterwards why Joubert had not called for replay assistance. But World Rugby said the television match official could only be called upon to rule on the build-up to scoring a try or an act of foul play.
“Its a penalty and that’s the way it works. You know they work both ways in all games and that’s life,” commented grateful Wallabies coach Michael Cheika.
The Scots came agonisingly close to reaching only their second ever semi-final, the last was in 1991, when Mark Bennett intercepted James Slipper’s pass for a try with five minutes remaining.
But defeat ended the worst World Cup ever for Europe’s main rugby nations. England were the first hosts to fail to reach the knockout stages and France went home in humiliation on Sunday after their crushing 62-13 defeat by the defending champions New Zealand in Cardiff.
“It is pretty tough,” said Scotland coach Vern Cotter, choking back emotion in the minutes after the match. “They never let go, they fought the whole way,” he said praising the Scottish performance.
Cotter did not comment on the penalty, except to say it was “an important decision.”
There was no such dramatic finale in Cardiff, although the Irish got back to within three points of the Pumas at 23-20.
They had trailed 17-0, to an Argentine side that had been almost to a man in tears at their national anthem rendition, after 15 minutes.
However, it was Argentina who finished the strongest against an Ireland side feeling the effects of losing four key players in the lead-up to the game and the effects of the win over France last Sunday.
Outstanding Pumas wing Juan Imhoff scored his second try of the game and equally impressive fullback Joaquin Tuculet touched down as well to give Argentina a record win over the Irish.
For Argentina it is their second semi-final, having done that in 2007 of whom several of their players survive in the present team.
“I feel very proud about the way we played and the way we won. And also the way we played at the end because we did everything we could to avoid conceding a try,” said Pumas coach Daniel Hourcade.
His outstanding skipper Agustin Creevy said they had achieved something special.
“Yesterday I was watching the All Blacks wondering when can we win by scoring 40 points and we did that today,” the hooker beamed.
For Ireland coach Joe Schmidt it was a moment to admire his opponents and the leaps and bounds they have taken, especially since being allowed to compete in the Southern Hemisphere competition, the Rugby Championship.
“It’s pretty hard not to respect the performance that Argentina put on,” said Schmidt, who can still take pride in how his side performed generally at the tournament.