A US judge has ruled immigration agents can no longer separate immigrant parents and children caught crossing the border from Mexico illegally, and must reunite those families that had been split up in custody.

United States District Court Judge Dana Sabraw granted the American Civil Liberties Union (ACLU) a preliminary injunction on Tuesday in a lawsuit filed over the family separations.

More than 2,300 migrant children were separated from their parents after President Donald Trump’s administration began a “zero tolerance” policy in early May, seeking to prosecute all adults who crossed the border illegally, including those traveling with children.

“The facts set forth before the court portray reactive governance responses to address a chaotic circumstance of the government’s own making,” Judge Sabraw wrote. “They belie measured and ordered governance, which is central to the concept of due process enshrined in our Constitution.”

The judge ordered the government to reunite parents with their children younger than five years old within 14 days of the order, and children five years old and older within 30 days of the order.

The ruling could force the administration to rapidly address confusion left by Mr Trump’s order, and government agencies to scramble to reunite families. The administration can appeal.

The ACLU had sued on behalf of a mother and her then six-year-old daughter, who were separated after arriving last November in the United States to seek asylum and escape religious persecution in Democratic Republic of Congo.

While they were reunited in March, the ACLU is pursuing class-action claims on behalf of other immigrants.

Mr Trump issued an executive order to end the family separations on June 20th, but the government has yet to reunite about 2,000 children with their parents.

The ACLU said on Monday that mr Trump’s order contained “loopholes”, and proposed requiring that families be reunited within 30 days, unless the parents were unfit or were housed in adult-only criminal facilities.

Before the preliminary injunction ruling, the US government urged Judge Sabraw not to require that it stop separating and quickly reunite migrant families after they illegally cross the US-Mexico border, saying the executive order last week “largely” addressed those goals.

Judge Sabraw, who was appointed by Republican President George W Bush, had on June 6th rejected the government’s bid to dismiss the case, saying forced separations could “shock the conscience” and amount to a violation of constitutional due process.