Recorded on a smartphone and uploaded multiple times on YouTube, the clip shows three girls dancing and singing along to the song in a room, on rooftops and in secluded alleys with three young men.
For the youths, the homemade video now watched one million times was merely an "excuse to be happy", but for the Iranian authorities it was "vulgar" breach of the Islamic republic's values.
Originally posted online in April, the clip gradually spread online before it led to the arrest of the dancers and their director on Tuesday for having "hurt" the country's strict moral codes, according to Tehran police chief Hossein Sajedinia.
The youths appeared on state television repenting for appearing in the clip, after the girls failed to properly observe hijab, a series of rules that oblige women in Iran to cover their hair and much of their body when outside.
Their arrest sparked international fury and criticism in the media and online, with many Iranians expressing shock and some observers questioning whether it was a "crime to be happy in Iran".
Supporting the young Iranians, Williams himself chimed in and hit out at their treatment, saying on Twitter and Facebook: "It's beyond sad these kids were arrested for trying to spread happiness."
Reports emerged Wednesday night that the dancers were released on bail, with one of the arrested girls, Tehran-based fashion photographer Reihane Taravati, saying on Instagram: "Hi I'm back."
- 'Right to happiness' -
The arrests came after President Hassan Rouhani -- a self-declared moderate who claims to be for more social freedoms -- reiterated in a weekend speech his calls for a relaxation of Internet censorship.
Rouhani's statements have irked the conservatives, who have long imposed limitations on the Internet, blocking millions of websites particularly social media platforms, including Facebook and Twitter, as well as YouTube.
The president appeared to send an apparent message of support to the dancers on Wednesday night, through a Twitter account associated with his office.
"Happiness is our people's right. We shouldn't be too hard on behaviours caused by joy," read a tweet quoting a June 2013 speech by Rouhani, who constitutionally has no power over Iran's judiciary.
The arrest is also the latest in a series of crackdowns on social disobedience, carried out by conservatives and traditionalists in the Islamic republic who are wary of an encroaching Western way of life.
In the summer of 2011, the police clamped down on hundreds of young men and women after detecting dark intentions in their participation at an organised water pistol fight in a Tehran park.
And the "morality police" hand out on a daily basis fines and verbal notices to women found to have broken the hijab rules, and in some cases make temporary arrests.
But there appears to be a growing undercurrent of young people in Iran willing to test the rules.
A Facebook campaign this month promoted women inside Iran posting pictures of themselves flouting the Islamic dress code, with the aim of sparking debate on whether women should have the right to choose what to wear.
In a counter move, two small pro-hijab rallies were held in Tehran as hardline men and women demanded authorities strike down on the rules.
- 'Youths need fun' -
The authorities appear to show leniency when a huge number of Iranians are involved in events that in other cases would be considered inexcusable.
This was demonstrated in June 2013 when police looked on as millions of people flooded the streets, dancing and singing for hours with joy over their country's qualification for the 2014 World Cup football tournament.
The celebrations were even acknowledged by supreme leader Ayatollah Ali Khamenei, the Islamic republic's ultimate authority who thanked the team for making Iranians "happy".
For a Tehran-based Western diplomat, the brief incarceration of the dancers this week -- reportedly only a few days -- came with a message despite the police chief's warning the youth against such "corrupt" acts.
"The establishment understands that youths need to have fun," said the diplomat who did not want to be named.
"So it comes down to protecting the Islamic state's values but stopping short of instituting a police state."