WASHINGTON — A state court in New Hampshire has ruled that the arrests of several people last summer who were charged with drug possession at an immigration checkpoint set up by the United States Border Patrol were unconstitutional under state and federal law.

Border Patrol agents working with state officials conducted what the American Civil Liberties Union had described as illegal drug searches. Sixteen residents were arrested in August at an immigration checkpoint set up on a major interstate highway about 90 miles from the Canadian border, where federal agents said they were looking for people trying to enter the country illegally.

In an order dated May 1, Judge Thomas A. Rappa Jr. of the New Hampshire Circuit Court threw out the arrests. “While the stated purpose of the checkpoints in this matter was screening for immigration violations, the primary purpose of the action was detection and seizure of drugs,” Judge Rappa concluded in the 14-page ruling, a copy of which was released on Friday.

The A.C.L.U. of New Hampshire had said the arrests violated New Hampshire’s state Constitution, which requires law enforcement officials to have a reasonable suspicion of a crime before stopping and searching individuals and their vehicles.