Nine Australian men who provoked anger in Malaysia by donning skimpy swimwear bearing the Muslim country's national flag at a Formula 1 race were released without charge on Thursday.
Four days after their arrest, the nine racing fans were brought to court to face potential charges of public indecency and national insult.
But after apologising -- and a dressing-down by a judge -- they were released.
The stunt by the nine men -- who were celebrating countryman Daniel Ricciardo's Malaysia Grand Prix win on Sunday -- offended some Malaysians and sparked a debate back home over boorish behaviour by Aussie sports fans abroad.
The detainees, all in their 20s, were dubbed the "Budgie Nine" by Australian media, a reference to the Speedo-style swimsuits known colloquially in Australia as "budgie smugglers".
A budgie, short for budgerigar, is an Australian parakeet. The swimwear is so named for leaving little to the imagination.
In scenes that quickly went viral, the men also quaffed beer from their shoes, imitating Ricciardo, who had celebrated by chugging champagne from his footwear.
Judge Harith Sham Mohamad Yasin called their conduct "totally inappropriate".
"It hurt the feelings of all Malaysians to display the flag in such a manner," he said.
The proceedings featured a moment of drama when defendant Thomas Whitworth fainted and collapsed to the floor as the nine stood during legal arguments.
Dehydration was blamed, and he soon recovered.
'Deepest regret' 
Earlier, Whitworth read out an apology expressing "our deepest regret".
"We had no idea our conduct would be deemed inappropriate, crass or even downright offensive to the citizens of this country," he said.
In the end, prosecutors sought a minor public nuisance charge, which brings a small fine.
But the judge ordered the defendants' release, citing the apology, their youth, and the four days already in custody.
Many in Malaysia laughed the episode off -- but others had demanded jail terms.
Ricciardo called the stunt "pretty harmless" in comments to Sydney's Daily Telegraph published on Thursday.
But Australian Foreign Minister Julie Bishop on Wednesday was less kind.
"What might be seen as a foolish prank or Aussie 'blokey' behaviour in Australia can be seen very differently in another country," she told Channel Nine.
"You have to respect the laws of the country you are visiting."
The nine include a staffer of Australian Defence Industry Minister Christopher Pyne.
The group arrived at court in the town of Sepang on Thursday in handcuffs, wearing suits and looking sombre.
There had been speculation they could face charges as serious as disrespecting Malaysia's flag, which can include six months in jail.
"All of the families in Australia and here today and around the world, we're just relieved the boys are going home," John Walker, father of "Budgie Nine" member Jack Walker, told reporters.
Before the court proceedings, staff placed the offending multi-coloured swimwear on a courtroom evidence table.
Foreign offenders accused of indecency in Malaysia are typically fined before being deported.
In June 2015, four Western tourists were each fined 5,000 ringgit ($1,200) for public obscenity and deported for taking nude photos atop Malaysia's Mount Kinabalu, a popular climbing peak.
The pictures, circulated online, incensed many partly because the mountain is considered sacred to local tribes.
An earthquake rocked the mountain days later, killing 18 people and prompting accusations that the nudists had angered mountain gods.