The U.S. government will no longer automatically extend residency to Cuban migrants arriving in the country without visas, President Barack Obama announced in a surprise decision Thursday.

The “wet foot, dry foot” policy was “designed for a different era,” the president said in a statement.

“By taking this step, we are treating Cuban migrants the same way we treat migrants from other countries,” he said. “The Cuban government has agreed to accept the return of Cuban nationals who have been ordered removed, just as it has been accepting the return of migrants interdicted at sea.”

The major policy change came with only days left in Obama’s presidency and after the president had worked for years to normalize diplomatic relations and chip away at the decades-old trade embargo. Obama capped his efforts with a visit to Havana last year. The warming of relations with the onetime Cold War enemy became one of his signature foreign policy achievements.

As the two countries became closer, Cuban nationals sought to take advantage of the immigration option before it potentially changed. The rule allowed Cubans who reached American soil to immediately apply for U.S. residency, with a quick pathway to citizenship. But the new policy, which was first reported by the Associated Press, ends this program. It also halts a George W. Bush-era program to recruit the island’s medical professionals, according to a congressional source who declined to be named ahead of the official announcement.

The “wet foot, dry foot” policy was long despised by Cuban officials, who said the policy encouraged people to take their lives into their hands by crossing the Florida straits illegally in anything that would float.

“This has been a big bone of contention for the Cubans throughout this whole process,” Chris Sabatini, a Cuba expert and the executive director of Global Americans, told HuffPost.

But in recent years, it’s also become unpopular among older generations of Cuban Americans in Miami, who contend that the policy benefits people who migrate for economic reasons rather than the people fleeing Cuba’s communist government, whom the policy was originally intended to benefit.

Ric Herrero, the executive director of #CubaNow, a group that has pressed to liberalize policy toward the island, said the changes would take a “highly contentious issue off [President-elect Donald] Trump’s plate before he enters the White House.”

“This is another concrete example that a policy of engagement yields results,” Herrero told HuffPost. “Our migratory policy toward Cuba has been one that’s problematic for many years but no one has been willing to touch it since Clinton’s first term.”

Roughly 28,400 Cuban nationals with criminal convictions have for years faced the possibility of deportation from the United States, but the Cuban government has refused to accept them.

Some 56,400 Cuban migrants entered the United States without visas last year, according to Customs and Border Protection ― nearly twice the number in 2014. White House Deputy National Security Advisor Ben Rhodes told reporters that they did not want to speculate publicly about the policy change and risk encouraging more people to come to the U.S. without authorization.

The 1966 Cuban Adjustment Act, from which the “wet foot, dry foot” policy originally derives, remains standing, though Obama administration officials urged Congress to repeal it. Cubans who reach U.S. soil will still be allowed to request asylum or other humanitarian relief under U.S. law, but immigration authorities will now treat those claims like those of other foreign nationals.

To carry out the new policy, the Cuban government agreed to accept back its nationals in cases where the U.S. starts the deportation policy sooner than four years after that person left the island, Department of Homeland Security Secretary Jeh Johnson said on a call with reporters. That leaves the vast majority of the longstanding cases pending, though Johnson said the Cuban government agreed to review the decisions on a case-by-case basis.

“Essentially what the agreement means is that past is past but that the future will be different,” Johnson said.

In Congress, supporters of engagement with Cuba applauded the move.

“It’s a move that brings our Cuba policy into the modern era while allowing the United States to continue its generous approach to those individuals and refugees with a legitimate claim for asylum,” Sen. Jeff Flake (R-Ariz.) said.

But the fact that the Obama administration is making a major policy change with only a week to go in his presidency concerned some congressional sources.

“There is absolutely a need to crack down on the small universe of people abusing the policy, but throwing the baby out with the bathwater AND on the 9th inning AND without Congressional consultation?” a congressional aide said in an email. “Hard to defend.”

There was dissent from Congress as well. Rep. Mario Diaz-Balart (R-Fla.), a longtime critic of Obama on Cuba policy, called the decision “yet another shameful concession to the Castro regime.”

“His policy has been a succession of betrayals of America’s longstanding commitment to human rights and freedom, and a betrayal of the Cuban people who have suffered under oppression for far too long,” Diaz-Balart said in a statement. “This last act of diminishing lifelines to Cubans languishing in totalitarianism is one final despicable betrayal of a people who deserve better from an American president.”

The policy change also could put President-elect Donald Trump in an uncomfortable position of agreeing with a last-minute move by the current president he often disparages. The president-elect’s team did not immediately respond to a request for comment on Obama’s decision, but Trump has previously criticized the “wet foot, dry foot” policy. “I don’t think that’s fair,” Trump said in February 2016. “I mean why would that be a fair thing?”

This was a breaking story and has been updated throughout.