Shortly after Nigeria’s law went into effect, Animashaun Azeez, 24, a university student here, arranged to meet somebody he had chatted with on Manjam, a social network for gay people. The person showed up, along with three plainclothes officers. Mr. Azeez said he spent three days in jail and was released only after his father, fearing publicity, paid off the police with about $900.

“Many L.G.B.T. people are getting into trouble day by day,” said Mr. Azeez, who after the episode became a volunteer for the Initiative for Equal Rights, a gay rights group in Lagos.

Violence against gay Nigerians has increased significantly, according to the country’s National Human Rights Commission. Most are attacked in the open by groups of men, some of whom call themselves “cleansers,” rights groups say.

But victims often do not report attacks for fear of being outed. Even men infected with H.I.V. are often reluctant to seek treatment at hospitals, fearing that the authorities will be called, said Stella Iwuagwu, executive director of the Center for the Right to Health, an H.I.V. patient and rights group based in Lagos.

“Before, these people were leading their lives quietly, and nobody was paying any attention to them,” Ms. Iwuagwu said. “Before, a lot of people didn’t even have a clue there were something called gay people. But now they know and now they are outraged. Now they hear that America is bringing all these foreign lifestyles. They are emboldened by the law. The genie has already left the bottle.”

The United States’ role comes as longstanding foes in its culture wars continue to move their fight to Africa. Many private supporters of equal rights for gay people in the United States, after landmark successes at home, are increasing their funding of gay causes abroad, especially in Africa.