The lawsuit against the controversial film was brought by a Brazilian Muslim group, the National Islamic Union, against YouTube owner Google Inc for posting on the Internet a film it said was offensive and a violation of the constitutional right to freedom of expression.
In his decision, Judge Gilson Delgado Miranda said the case juxtaposed freedom of expression and the need to protect individuals or groups of people from action that might incite religious discrimination.
Miranda concluded that banning something illegal should not "offend" freedom of thought and expression, according to the ruling posted online by Estado de S. Paulo newspaper.
It wasn't the only Brazilian court ruling against Google on Tuesday. Earlier, an elections court ordered the arrest of Google's most senior executive in Brazil after the company failed to take down YouTube videos attacking a local mayoral candidate.
The legal challenges underline broader questions about Google's responsibility for content uploaded by third parties to its websites, such as the anti-Islam video, which mocked the Prophet Mohammad and sparked a wave of protests and violence in the Muslim world.
Fifteen people were killed in Pakistan during demonstrations over the video on Friday. People involved in the film, an amateurish 13-minute clip of which was posted on YouTube, have said it was made by a 55-year-old California man, Nakoula Basseley Nakoula.