WASHINGTON — The Senate voted late on Thursday to prohibit the government from imprisoning American citizens and green card holders apprehended in the United States in indefinite detention without trial.

While the move appeared to bolster protections for domestic civil liberties, it was opposed by an array of rights groups who claimed it implied that other types of people inside the United States could be placed in military detention, opening the door to using the military to perform police functions.

The measure was an amendment to this year’s National Defense Authorization Act, which is now pending on the Senate floor, and was sponsored by Senators Dianne Feinstein, Democrat of California, and Mike Lee, Republican of Utah. The Senate approved adding it to the bill by a vote of 67 to 29.

“What if something happens and you are of the wrong race in the wrong place at the wrong time and you are picked up and held without trial or charge in detention ad infinitum?” Ms. Feinstein said during the floor debate. “We want to clarify that that isn’t the case — that the law does not permit an American or a legal resident to be picked up and held without end, without charge or trial.”

The power of the government to imprison, without trial, Americans accused of ties to terrorism has been in dispute for a decade.

Last year, in the previous annual version of the National Defense Authorization Act, Congress included a provision stating that the government had the authority to detain Qaeda members and their supporters as part of the war authorized shortly after the terrorist attacks of Sept. 11, 2001. But lawmakers could not decide whether that authority extended to people arrested on American soil, and so they left it deliberately ambiguous.

Ms. Feinstein, arguing that law enforcement officials have proved capable of handling cases that arise on domestic soil, said the amendment was intended to “clarify” that the government may not put Americans arrested domestically in military detention.

Senator Kelly Ayotte, Republican of New Hampshire, objected to the restriction on security grounds, saying that even American citizens arrested inside the United States on suspicion of planning a terrorist attack for Al Qaeda should be held under the laws of war and interrogated without receiving the protections of ordinary criminal suspects, like a Miranda warning of a right to remain silent.

From the other direction, an array of civil liberties and human rights groups — including the American Civil Liberties Union and Human Rights First — objected to the amendment because it was limited to citizens and lawful permanent residents, as opposed to all people who are apprehended on United States soil.

“Senator Dianne Feinstein has introduced an amendment that superficially looks like it could help, but in fact, would cause harm,” said Chris Anders of the A.C.L.U.

But on the floor, Ms. Feinstein said that she limited the amendment to citizens and green card holders because she believed that language would “get the maximum number of votes in this body.”

The Senate on Thursday also passed, 94-0, a series of additional American sanctions on Iran. The amendment would impose penalties on individuals selling commodities to Iran that might be used in ship-building or the nuclear program, including aluminum and steel. It also threatened countries, like Turkey, which are buying Iranian oil with gold, in an effort to circumvent banking sanctions.

The current language does not give the president the power to issue waivers, as he has done for countries like Japan, South Korea and India that buy Iranian oil. The White House has opposed the amendment, with officials saying they fear it could “threaten to confuse and undermine” existing effort to get allies, China and other countries to impose other sanctions already in the pipeline.

Also on Thursday, the Senate voted, 62 to 33, for a nonbinding amendment calling for an accelerated withdrawal of United States combat forces from Afghanistan. The measure was sponsored by Senator Jeff Merkley, Democrat of Oregon, and was backed by 13 Republicans.