WASHINGTON — The American Civil Liberties Union has sued three government agencies on behalf of immigration activists who were allegedly surveilled and flagged for questioning when crossing the U.S.-Mexico border because of their work with immigrants, according to court documents filed in the Central District of California.

The complaint alleges that the three plaintiffs — activists Nora Elizabeth Phillips, Erika Da Cruz Pinheiro and Nathaniel Garrett Dennison — were targeted for "detention and interrogation" under a "secret investigative program designed to monitor these humanitarian workers ... and impede their ability to travel." The suit names Immigration and Customs Enforcement, Customs and Border Protection and the FBI as defendants, as well as FBI Director Christopher Wray and Acting ICE Director Matthew Albence.

In March, NBC News and NBC 7 San Diego uncovered details of the program after obtaining a CBP list of names of journalists, activists and lawyers who were to be stopped by CBP agents when crossing the border. The ACLU cited the reporting as the impetus for the lawsuit.

Erika Pinheiro, Nora Phillips and Nathaniel Dennison. Al Otro Lado; U.S. Government

"The disclosure of the secret program spurred outrage from civil society organizations, prompted members of Congress to call for an inquiry into the agencies' actions, and led Customs and Border Protection's Inspector General to initiate its own investigation into surveillance," the lawsuit said.

Read the KNSD/NBC 7 San Diego version of this story.

The list obtained in March targeted only immigration workers in the San Diego area, but an NBC News report later found that activists and lawyers in other areas, such as El Paso, were also targeted.

Two immigration lawyers stopped in El Paso said they were held for hours and asked to hand their cell phones over to immigration agents so that they could obtain their contacts.

In the complaint, the ACLU said the "plaintiffs have been singled out and targeted solely because of their protected speech and association, including their provision of legal counsel to asylum seekers, their association with others providing humanitarian aid, and the assistance they provided to clients seeking to redress or to express themselves publicly."

When the first report was published in March, the Department of Homeland Security, which oversees CBP and ICE, said the individuals were targeted as part of an investigation into violence that erupted at the San Diego-Tijuana border in late 2018 when a so-called migrant caravan arrived. But many of those targeted have said they were nowhere near San Diego at the time and had no involvement with the caravan.

John Sandweg, former acting director of Immigration and Customs Enforcement, told NBC News in March that border agents should never target people at the border for inspection based on their profession, including their work with asylum seekers.

The ACLU is asking the court to issue an injunction that would declare the activity of the border agents unlawful under the First Amendment and award damages.

Plaintiff Nora Phillips is the co-founder of Al Otro Lado, a Los Angeles-based nonprofit that provides legal and mental health services to migrants. Pinheiro is a co-founder of the same group and organizes legal clinics inside Mexico. Dennison is a documentary filmmaker and shelter volunteer.

DHS did not immediately respond to a request for comment.