The Supreme Court granted the Biden administration permission on Thursday to end a Trump-era immigration policy that required asylum seekers to remain in Mexico while their cases were reviewed, putting an end to a year-long legal battle over a policy critics say contributed to a humanitarian crisis on the border.

Chief Justice John Roberts requested a 5-4 vote. Associate Justice Brett Kavanaugh and the court’s liberal bloc joined him. Associate Justices Samuel Alito, Neil Gorsuch, Clarence Thomas, and Amy Coney Barrett all voted against the decision.

Roberts stated in his final opinion for the 2021-2022 term that the lower court’s ruling against the administration “imposed a significant burden on the executive’s ability to conduct diplomatic relations with Mexico.” Because, as Roberts pointed out, the US cannot unilaterally return Central American migrants to Mexico. These payments must be worked out with Mexican officials.

The decision was a rare victory for Biden at the conservative Supreme Court, and it allowed the administration to reverse a policy implemented by President Donald Trump.

In his dissent, Alito blamed the administration for allowing “untold numbers of aliens into this country who are very likely to be removed if they show up for their removal hearings.”

“This practice clearly violates the clear terms of the law,” Alito said, “but the court ignores it.” As part of its effort to reduce immigration, the Trump administration implemented the “remain in Mexico” policy, also known as Migrant Protection Protocols, in January 2019. It requires asylum seekers from Central America and other countries to wait in Mexico while their claims are reviewed. According to court records, the federal government had enrolled 68,000 people in the program by the end of 2020.

In order to fulfill a campaign promise, Biden canceled the program last year. Texas and Missouri filed a lawsuit, claiming that the Department of Homeland Security violated the law by terminating the program without explaining why. In December, the United States Court of Appeals for the Fifth Circuit sided with the states.

Federal law requires DHS to detain migrants while their asylum claims are processed, but Congress has not appropriated enough funds to meet that requirement for the vast majority of migrants. According to federal officials, DHS had funding for only 32,000 detention beds out of the 220,000 encounters border agents had with immigrants on the southwest border in March.

The Biden administration never disputed that detaining those immigrants is required by law. The question was what to do with those people in the absence of funding from Congress to carry out the requirement. According to Texas and Missouri, the law requires that the majority of those people be returned to Mexico. Biden officials argued that the law makes no such requirement, and that no previous administration, Republican or Democrat, had interpreted it in that way.

Instead, the Biden administration ended up allowing thousands of migrants to enter the country to await hearings. According to the administration, the arrangement allows officials to prioritize people for detention who are most likely to commit crimes or flee.

The program is similar to but distinct from Title 42, which was implemented in 2020 and expedites the removal of asylum seekers due to the COVID-19 pandemic. Biden attempted to halt the program, but the effort was halted by a federal court.

The lawsuits are being fought as the country faces a surge in migrants at the southern border. In April, US Customs and Border Protection encountered 234,088 people at the border, the highest monthly total in 22 years.