The US judge said attorneys for the government had failed to prove their case

A federal judge in California on Friday blocked a bid by the Trump administration that would have allowed for undocumented migrant children to be detained indefinitely.

The decision by US District Judge Dolly Gee relates to the so-called Flores Agreement which stipulates that the government could not detain migrant children for more than 20 days.

In the face of a massive influx of migrant families crossing into the United States this year, the White House sought to scrap the 22-year-old agreement, in order to deter migrant expectations that they would be released after being arrested by border agents.

President Donald Trump's administration has faced numerous court challenges over its efforts to curb migration.

"The blessing or the curse -- depending on one's vantage point -- of a binding contract is its certitude," Gee said in her ruling.

"Defendants cannot simply ignore the dictates of the consent decree merely because they no longer agree with its approach as a matter of policy," she added.

Gee said attorneys for the government had failed to prove their case and could have sought Congressional action to reverse the Flores agreement.

"Having failed to obtain such relief, defendants cannot simply impose their will by promulgating regulations that abrogate the consent decree's most basic tenets," Gee said. "That violates the rule of law. And that this Court cannot permit."

The Department of Justice said the administration was "disappointed" with the ruling and would continue to work "to restore integrity to our immigration system."

A spokesperson called the Flores Agreement "outdated" and said "the government has done exactly what the Agreement required: issue a comprehensive rule that will protect vulnerable children, maintain family unity, and ensure due process for those awaiting adjudication of their immigration claims."

A coalition of 20 US states had filed suit against the Trump administration after it announced that it planned to scrap the Flores rule.

Human rights groups had also criticized the proposed new rule and vowed to challenge it in court.

"This ruling is a victory for immigrant children and we are thrilled that the Flores protections will stand," the National Center for Youth Law said in a statement following Friday's ruling. "However, we fully expect the administration will continue its relentless campaign to abolish basic protections for children, imprison them without any oversight and erroneously blame the Flores Settlement Agreement for impacting migration patterns."

Trump made cracking down on illegal immigration a key part of his 2016 presidential campaign platform.

In 2018, he launched a "zero tolerance" policy that saw more than 2,300 children separated from their parents at the border, before the government backed down amid a massive public outcry.