SAN FRANCISCO — The Trump administration’s policy of returning asylum seekers to Mexico while their cases wind through immigration courts violates U.S. law by putting the migrants in danger and depriving them of the ability to prepare their cases, a lawsuit filed Thursday by civil liberties groups claims.

The lawsuit in federal court in San Francisco seeks a court order blocking the Department of Homeland Security from carrying out the policy that took effect in January at the San Ysidro border crossing in San Diego.

The launch followed months of delicate talks between the U.S. and Mexico and marked a change to the U.S. asylum system that the administration and asylum experts said was unprecedented.

Homeland Security Secretary Kirstjen Nielsen said the policy is “a vital response to the crisis at our southern border.”

Mexican officials have sent mixed signals on the crucial point of whether Mexico would impose limits on accepting families. The effort began at a San Diego crossing with Tijuana, Mexico for adults only, but U.S. officials have started to include families, which currently account for nearly half of Border Patrol arrests.

“Instead of being able to focus on preparing their cases, asylum seekers forced to return to Mexico will have to focus on trying to survive,” according to the lawsuit filed by the American Civil Liberties Union, the Southern Poverty Law Center and the Center for Gender & Refugee Studies. “These pressures may deter even those with the strongest asylum claims to give up, rather than endure the wait under such conditions.”

Steven Stafford, a spokesman for the U.S. Department of Justice, said Congress has “explicitly authorized” Homeland Security officials to return migrants to a “contiguous foreign territory” during their immigration proceedings.

“The Department of Justice will defend the Department of Homeland Security’s lawful actions in court,” he said in a statement.

Homeland Security Secretary Kirstjen Nielsen said the policy is “a vital response to the crisis at our southern border.”

READ MORE: New Trump policy forces some asylum seekers to wait in Mexico. Is that legal?

“The Department of Homeland Security is exercising its statutory authority to help alleviate this humanitarian and security crisis and secure our nation,” she said.

Border Patrol arrests, the most widely used gauge of illegal crossings, have risen sharply over the last year but are relatively low in historical terms after hitting a 46-year low in 2017. Many are Central American asylum-seeking families and children who immediately turn themselves in to agents.

The lawsuit was filed the day after the U.S. returned the first children to wait in Mexico. Unaccompanied children and Mexican asylum seekers are exempt from the policy.

All 13 children returned with their families, said a Mexican official who was not authorized to be quoted by name and spoke on condition of anonymity. The first 10 arrived in Tijuana, Mexico, on Wednesday, and another three arrived Thursday.

The first asylum-seeking families who returned included a 1-year-old, according to the lawsuit.

The lawsuit was filed on behalf of 11 asylum seekers from Central America, many of whom have already experienced violence in Mexico, according to the lawsuit.

One plaintiff, identified as Howard Doe, escaped after being kidnapped and held by a drug cartel for more than two weeks while traveling through Mexico to reach the U.S. border, the lawsuit says. It adds that the asylum seekers don’t have the money to stay in Mexico while they fight for asylum or family there that can help them through the legal process.

The lawsuit accuses the administration of violating immigration laws that limit who can be sent back to Mexico, require that migrants have a meaningful opportunity to apply for asylum and prohibit the return of individuals to face persecution, torture or cruel treatment. It also says the administration implemented the new policy without a “reasoned explanation” in violation of administrative requirements.

READ MORE: Trump says there’s a ‘crisis’ at the border. Here’s what the data says