Federal immigration officials agreed to a court settlement late Wednesday that prohibits them from randomly checking the papers of passengers on domestic flights, ending a two-year lawsuit that was filed after Customs officers did just that on a flight from San Francisco to New York City.

In 2017, domestic passengers on a Delta Airlines flight arriving at John F. Kennedy International Airport were met by Customs officers who were looking for a fugitive. All passengers were asked to show their identification upon deplaning, which led to a lawsuit filed by the American Civil Liberties Union on behalf of nine passengers claiming a violation of the passengers' Fourth Amendment protections against unreasonable searches and seizures.

Attorneys for Customs and Border Protection signed a settlement on Wednesday that requires the agency to instruct all of its Customs officers working at airports that they cannot have a policy of "suspicionless document checks" or conduct any operations that violate the Fourth Amendment.

The agency can still conduct identification checks of passengers deplaning after domestic flights, but they must verbally advise passengers that the checks are voluntary, request the airline to make a public announcement telling passengers that the screening is voluntary, and officers must situate themselves in a way to ensure that "passengers who decline to cooperate have an unimpeded path to exit."

"If a passenger asks, officers should communicate that passengers who decline to cooperate will not suffer any enforcement as a result," read the settlement.

Under the agreement, Homeland Security is also required to pay $40,000 in lawyer fees to the ACLU and a private law firm — Covington & Burling — that represented the nine passengers. ACLU attorneys called the settlement a major victory for the rights of passengers and the integrity of the Fourth Amendment.

"The Constitution protects passengers deplaning domestic flights just as it protects people on the street or in a car," Hugh Handeyside and Anna Diakun, attorneys with the ACLU’s National Security Project, said in a statement. "(Customs and Border Protection) is bound by those protections, and this settlement helps make sure the agency stays within those bounds."

Customs and Border Protection did not respond to a request for comment.

The incident that prompted the lawsuit came during a tumultuous time at U.S. airports. President Donald Trump had just assumed office the month before and swiftly ordered his controversial travel ban, which snarled traffic at airports and led to a flurry of lawsuits around the country.

On Feb. 22, 2017, domestic passengers on a Delta Air Lines flight that landed at John F. Kennedy International Airport were told by the flight crew that they had to show their IDs to Customs officers in order to deplane, according to the lawsuit. Agents blocked the doorway and checked every person's documents before allowing them to leave, according to the suit.

Kelley Amadei, one of the passengers on the flight and a plaintiff in the ACLU lawsuit, said that whether the checks were voluntary or not, they certainly felt mandatory that day.

"I felt in the moment like I had no choice but to comply with this police-state tactic," she said.

Customs and Border Protection, which oversees the Customs officers who man the nation's airports, said at the time that its officers were helping Immigration and Customs Enforcement (ICE) find a fugitive who may have been on the flight. They did not have the person's photo, only his name, which led them to check the IDs of people on the flight.

"The individual was determined not to be on the flight," Customs and Border Protection said at the time.