President Trump lost two big immigration court rulings Tuesday, after a federal judge in California shot down his attempt to limit asylum claims and another judge in Michigan ordered the administration to release nearly 100 Iraqi immigrants living in the U.S. illegally who had been detained as part of a travel ban-related deal.

In the asylum case, the judge, an Obama appointee, said the president was illegally trying to circumvent Congress to rewrite immigration laws — a charge Mr. Trump and fellow Republicans used to lodge at President Obama.

The Michigan judge, also an Obama appointee, was even more harsh, accusing Department of Homeland Security officials of misleading the court to keep Iraqi migrants locked in detention, even though the government knew there was little chance of most of them being deported.

SEE ALSO: Judge blocks Trump asylum changes: Caravan can demand protections even after illegal entry

Mr. Trump was furious over the asylum ruling, complaining that federal judges in the 9th judicial circuit, which covers the West Coast, aren’t giving him a fair shake. He said nearly every case filed against him there “means an automatic loss no matter what you do, no matter how good your case it,” and he vowed some future retribution.

“It’s a disgrace,” he said of Judge Jon S. Tigar’s asylum decision. “In my opinion, it’s a disgrace what happens with the 9th Circuit. We will win that case in the Supreme Court of the United States.”

But for now, Judge Tigar’s ruling leaves the government vulnerable to flimsy asylum claims by immigrants living in the U.S. illegally who are part of the migrant caravans massed on the Mexico side of the border.

SEE ALSO: Judge orders feds to release dozens of illegal immigrants from Iraq

Homeland Security and the Justice Department had written new asylum rules this month banning people who illegally crossed the U.S.-Mexico border from lodging asylum claims, saying it was too much of an enticement to illegal immigration. Those who showed up at official border crossings still would be allowed to claim asylum, even if they weren’t authorized to enter.

Judge Tigar, though, said federal law is clear, and it grants everyone the chance at asylum.

“Whatever the scope of the president’s authority, he may not rewrite the immigration laws to impose a condition that Congress has expressly forbidden,” the judge ruled.

Homeland Security Secretary Kirstjen Nielsen vowed an appeal, but said her officers and agents will follow the judge’s restraining order.

“We are looking very carefully at what the judge has ruled and we will comply with it,” she said.

Ms. Nielsen insisted Mr. Trump, in enacting the asylum ban, was flexing legal powers given him to exclude any class of alien from the U.S. when he deems it in the interests the nation. She said those powers were upheld this year by the Supreme Court in the travel ban case.

The travel ban also played a role in Tuesday’s other big adverse ruling for Mr. Trump.

Mr. Trump’s original travel ban policy, announced in January 2017, had targeted seven majority-Muslim nations for a near-total ban on their citizens entering the U.S. — including Iraq.

But after intense negotiations, Iraq was dropped from the second version, announced in March 2017. U.S. officials said at the time that Iraq earned its way off the ban list by agreeing, after years of recalcitrance, to take back its deportees.

Soon after, U.S. Immigration and Customs Enforcement rounded up hundreds of Iraqis, some who had been in the country for decades while their home government wouldn’t take them back.

Immigrant-rights groups sued, arguing the roundup was unfair after so many years and urging that the migrants be given a new chance to claim protections here.

That argument is still being fought — but in the meantime, the American Civil Liberties Union, which is representing the Iraqis, uncovered evidence that the travel ban deal with Iraq was mostly a chimera.

ICE officials admitted there is no written agreement, and instead they must seek permission for every deportee — permission that Iraq usually denies, unless the deportee has said he or she wants to be sent back. Advocates said that’s rarely the case for people in the U.S.

U.S. District Judge Mark A. Goldsmith said since there’s little chance they can be deported, the government must release them.

His ruling likely will free about 95 Iraqis over the next month, the ACLU said.

“Families have been shattered,” the judge wrote in his ruling, pointing to Iraqis who have been locked up for two years or more, away from their relatives.

“Petitioners’ only crime is being caught between the United States and Iraq’s diplomatic tug-o-war over repatriation. Nonetheless, more than half of the detainees are being held in penal institutions under the same conditions as those convicted of crimes,” he ruled. “The public interest overwhelmingly favors freedom over mass detention in these circumstances.”

Judge Goldsmith also said the misleading statements ICE made in the case deserve punishment, in what amounted to a severe rebuke. He said the nature of the sanctions is still to come.

Miriam Aukerman, a senior staff attorney at the Michigan ACLU, said the case exposed serious malfeasance at ICE, and she said if the government was willing to “lie in a case that is this high-profile,” there’s no telling what’s going on in other detention cases.

“Our real concern here is this is the tip of the iceberg,” she said. “We spent almost a year fighting for every scrap of paper to prove that ICE lied to the court. … What we got showed that ICE lied. And it showed that those misrepresentations directly led to the incarceration of over 100 people.”

The asylum and Iraqi deportation rulings continue what, save for the travel ban and border wall, have been a serious losing streak for the administration on immigration cases. Mr. Trump’s proposed DACA phaseout, Homeland Security’s attempts to cancel Temporary Protected Status for migrants from disaster-stricken countries, the Justice Department’s sanctuary city crackdown, Mr. Trump’s zero-tolerance border policy that separated immigration families crossing into the U.S. illegally and an attempt to add a citizenship question to the 2020 census have all met with resistance from federal judges.