But whether the United States will impose punitive sanctions on Uganda remains to be seen.

American development aid includes funding for AIDS treatment, among other things. Military cooperation is aimed in part at the hunt for the warlord Joseph Kony and dealings with terrorist groups in Somalia. A senior administration official said Friday in an interview that United States policy objectives and the interests of Ugandans were being weighed in “a thoughtful, deliberate way.”

“We have not yet made decisions,” the official said, speaking on condition of anonymity because of rules against public discussion of internal talks. “We are working on this very intensively. There will be real consequences.”

At the United Nations, Mr. Ban expressed alarm. After meeting with the Ugandan envoy last week, Mr. Ban issued a statement calling on Uganda to revise or repeal the measure, a prospect that seems unlikely. Even the United Nations needs Mr. Museveni’s cooperation on many conflicts in and around Uganda, including the one in South Sudan.

For his part, Mr. Museveni has so far played to his domestic audience, rebuffing outside meddling and saying that his country would do fine without aid. There is plenty of aid to Africa coming from China, which tends not to wag its finger about human rights.

Mr. Museveni’s bluster also showed the limits of international influence and the backlash that international support can engender.

“It’s quite common, when you see a ratcheting up of pressure from domestic groups or foreign governments,” said Laurence R. Helfer, a Duke University law professor who studies international gay rights. “There is a period of counterreaction; we’re seeing that now.”

The turning point came in 2011, when the United Nations Human Rights Council passed a landmark resolution, led by South Africa, to extend human rights principles to lesbians and gay men around the world.