Jewish groups in San Francisco were celebrating on Thursday evening after a judge ordered the proposed ban on circumcision to be removed from a ballot.
Judge Loretta Giorgi ruled that the measure was "expressly preempted" because under Californian state law cities cannot regulate medical practice.
She said that evidence showed that circumcision was "a widely practiced medical procedure" and therefore could not be limited. She also said it would violate the constitutionally protected right to freedom of religion to impose a ban, because circumcision is part of both Jewish and Muslim worship.
The proposal was due to be voted on in November and if it had been successful, would have made parents liable for a fine or even a prison sentence if they permitted the circumcision of boys under the age of 18..
Judge Giorgi's ruling followed a lawsuit last month calling for the removal of the measure from the ballot, brought by a coalition of Jewish, Muslim and medical groups.
The ruling was praised by Brian McBeth, a doctor involved in the case. He said in a statement that he was pleased the judge had recognised the need to keep law enforcement out of private decisions.
The Anti-Defamation League also welcomed it as "a critical affirmation of religious freedom and parental rights". Nancy Appel, the ADL's associate regional director, said: "The Court has rightly upheld the freedom for Jews and Muslims in San Francisco to choose to circumcise their children in accordance with long-standing religious tradition."
She also said she was heartened by the judge's decision not to accept the comparison, made by supporters of a ban, between female genital mutilation and male circumcision. "It is completely inappropriate and offensive to compare the two practices," she said.
Campaigners for the ban said they were considering an appeal.