Fans have posted similar "Happy" videos from around the world, showing people dancing down streets.
While speaking at an exhibit opening in Paris Monday, Williams said he has "the utmost respect for people's religious views" and doesn't know much about Iranian law.
But he added: "The present is a gift, and if you just want to celebrate your happiness, you should be allowed to do that."
"They are just dancing," he also said.
It's beyond sad these kids were arrested for trying to spread happiness http://t.co/XV1VAAJeYI— Pharrell Williams (@Pharrell) May 21, 2014