NEW YORK (AP) — President Donald Trump's administration didn't offer "legally adequate reasons" for ending a program that spared many young immigrants from deportation if they were brought to the U.S. as children, a judge ruled Tuesday as he ordered the program to continue.

U.S. District Judge Nicholas G. Garaufis in Brooklyn said in a written order that the Republican president "indisputably" has the power to end the Deferred Action for Childhood Arrivals (DACA) program but relied on flawed legal positions in doing so.

"The Trump administration should be able to alter the policies and priorities set by its predecessor," Garaufis said.

He said his order does not require the government to grant any particular DACA applications or renewal requests.

The ruling came in lawsuits brought by immigration rights groups and 15 states and the District of Columbia.

Justice Department spokesman Devin O'Malley said the order doesn't change the government's position that DACA was an "unlawful circumvention of Congress."

"DACA was implemented unilaterally after Congress declined to extend these benefits to this same group of illegal aliens," he said.

O'Malley added that the Department of Homeland Security "acted within its lawful authority in deciding to wind down DACA in an orderly manner" and looked forward to vindicating its position in future litigation.

Attorney General Jeff Sessions has said then-President Barack Obama's decision to implement DACA was an unconstitutional exercise of authority. Known as "Dreamers," participants in the program were brought to the U.S. illegally as children or came with families who overstayed visas.

"Today's ruling gives hope to me and dreamers around the country," said Eliana Fernandez, a plaintiff in the case. "We are thrilled with this preliminary injunction."

Karen Tumlin, legal director of the National Immigration Law Center, said the ruling shows that how Trump ended DACA "was not just immoral, it was unlawful."

Garaufis said the Trump administration relied on an "erroneous" belief the program was unconstitutional. His ruling mirrors one issued in San Francisco in January.

"DACA is not unconstitutional simply because it was implemented by unilateral, executive action without express congressional authorization," Garaufis said. He said Congress has acknowledged the executive branch's power to decline to remove some vulnerable immigrants otherwise subject to deportation from the country.

The judge ordered the government to let people already in the DACA program continue enjoying protections but declined to guarantee the program to new applicants.

Garaufis said the authority for his ruling stems from the Administrative Procedure Act, which lets parties harmed by federal agencies get judicial review of agency decisions when they are arbitrary, capricious, an abuse of discretion or do not follow the law.

He said the plaintiffs were likely to succeed on their claim that the DACA rescission was arbitrary and capricious.

Garaufis said the decision to end the program appeared to rest exclusively on a legal conclusion that the program was unconstitutional and violated the APA and the Immigration and Nationality Act.

"Because that conclusion was erroneous, the decision to end the DACA program cannot stand," he said.

___

Associated Press Writer Deepti Hajela contributed to this report.