MOSCOW — While Russian lawmakers debated a bill that would outlaw “homosexual propaganda,” nationalist and religious demonstrators on Friday attacked gay rights advocates who had gathered outside the lower house of Parliament to protest the legislation.

The attackers, some singing religious hymns, hurled eggs and paint at the gay rights advocates, and shouted “Moscow is not Sodom!” In response, gay rights advocates shouted: “Fascism will not pass!” and “Moscow is not Iran!” Skirmishes broke out, and the police arrested about 20 people — most them opponents of the bill, who were accused of demonstrating without a permit.

Inside, lawmakers voted 388-1 for the bill, which would make it a federal crime in Russia to distribute “homosexual propaganda,” with violations punishable by fines of up to $16,000. One lawmaker abstained. The bill must be approved by the lower house two more times before being sent to the upper chamber. Similar laws have been approved by a number of regions and municipalities, including St. Petersburg, where supporters of the restriction tried unsuccessfully to use it to bring charges against the pop star Madonna.

The overwhelming vote fits with a larger pattern in recent months of the Russian government drawing closer to the Russian Orthodox Church and favoring so-called traditional values over individual liberties or behavior perceived as representing more modern, Western influences. This has included the aggressive prosecution and conviction of members of the punk band Pussy Riot for a stunt in Moscow’s main cathedral, and legislation imposing new restrictions on the Internet in the name of protecting children from pornography.