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.”