A federal judge on Monday blocked the Trump administration's policy requiring Central American asylum-seekers to wait in Mexico while their cases are decided in the U.S., ruling that Department of Homeland Security overstepped its legal authority.

That policy was one of the last attempts by outgoing Homeland Security Secretary Kirstjen Nielsen to gain control of the southern border, which has seen such an increase in illegal crossings that she resigned from her post over the weekend.

U.S. District Judge Richard Seeborg in San Francisco ordered the Trump administration to allow the plaintiffs in the case — 11 migrants from El Salvador, Guatemala, and Honduras — to enter the U.S. within two days. He issued a nationwide preliminary injunction that prevents the administration from forcing future asylum-seekers back into Mexico. The order goes into effect on Friday.

Seeborg, who was nominated by former President Barack Obama, ruled that the Trump policy was not properly implemented and violated both U.S. laws and the 1951 United Nations Convention on Refugees, which the U.S. is a party to. The asylum-seekers, Seeborg ruled, were already fleeing dangerous conditions in their home countries, only to be returned to Mexican border towns "where they face undue risk to their lives and freedom."

Trump complained of Seeborg's ruling Monday night on Twitter: "A 9th Circuit Judge just ruled that Mexico is too dangerous for migrants. So unfair to the U.S. OUT OF CONTROL!" he said.

The ruling marks the third straight time the Trump administration has been shot down in its attempts to limit or halt asylum-seekers who have been arriving at the U.S. border in record numbers.

"Try as it may, the Trump administration cannot simply ignore our laws in order to accomplish its goal of preventing people from seeking asylum in the United States," said Judy Rabinovitz, deputy director of the ACLU's Immigrants' Rights Project who argued the case.

In December, another federal judge struck down the Department of Justice's attempt to cut off asylum for victims of domestic abuse and gang violence. In November, another federal judge struck down Justice's attempts to cut off asylum for people who crossed into the country illegally, which is allowed under U.S. law.

In that case, U.S. District Judge Jon Tigar wrote that Trump "may not rewrite the immigration laws."

Monday's ruling follows a suit filed by Central American migrants who were among the first to be returned to Tijuana after requesting asylum at the San Ysidro Port of Entry in southern California, and several humanitarian groups that have been assisting migrants.

The policy, officially called the "Migrant Protection Protocols" but informally referred to as the "Remain in Mexico" plan, started in January at the San Ysidro Port of Entry in southern California. The policy has expanded to the Calexico Port of Entry about 120 miles east of San Ysidro, and Homeland Security officials say the plan is to gradually roll it out to all other ports along the U.S.-Mexico border.

It allows migrants from countries other than Mexico to request asylum at U.S ports of entry, but then requires them to return to Mexico to wait for a decision. Previously, asylum seekers were released into the U.S. and given a notice to appear in immigration court to proceed with their case.

'Incredibly hard jobs':Nielsen resignation: Donald Trump's Cabinet agencies are increasingly led by 'acting' secretaries

More:'It was long past time for her to go': Dems welcome Kirstjen Nielsen's departure as DHS secretary

The U.S. and Mexican governments had been negotiating a joint plan, where Mexico would assume responsibility of the waiting asylum applicants, but when those talks broke down, the Trump administration announced in December it would unilaterally implement the policy, forcing Mexico and collection of humanitarian groups to care for those migrants in Mexico.

Nielsen has argued that the policy is needed — and allowed under law — to stem the flood of Central American migrants who are taking advantage of immigration "loopholes" by requesting asylum knowing they will be allowed to stay in the country.

In the 2017 fiscal year, Border Patrol agents apprehended 6,301 members of family units a month. In 2018, that rose to 8,934 a month. In the first five months of 2019, it jumped to 27,230 a month.

The Trump administration says those numbers represent a security and humanitarian crisis that forced them to implement the new policy forcing all those asylum-seekers to stay in Mexico.

"The (Migrant Protection Protocols are) a lawful implementation of DHS's broad prosecutorial discretion over when and how to initiate removal proceedings…and whether to limit entry into the country during the pendency of those proceedings," Justice Department lawyers wrote in a court filing.

Advocacy groups say the plan puts already-traumatized refugees in yet another traumatizing situation by fending for themselves in northern Mexico, a region that can be incredibly dangerous for people with no family there, no connections, and no protection.

"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," read the lawsuit. "These pressures may deter even those with the strongest asylum claims to give up, rather than endure the wait under such conditions."

Several of the first asylum-seekers returned to Mexico filed a lawsuit in February, leading to Seeborg's decision.