President Barack Obama announced Thursday he is ending a longstanding immigration policy that allows any Cuban who makes it to U.S. soil to stay and become a legal resident.

The repeal of the "wet foot, dry foot" policy is effective immediately. The decision follows months of negotiations focused in part on getting Cuba to agree to take back people who had arrived in the U.S.

"Effective immediately, Cuban nationals who attempt to enter the United States illegally and do not qualify for humanitarian relief will be subject to removal, consistent with U.S. law and enforcement priorities," Obama said in a statement. "By taking this step, we are treating Cuban migrants the same way we treat migrants from other countries. 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 Cuban government praised the move. In a statement read on state television, it called the signing of the agreement "an important step in advancing relations" between the U.S. and Cuba that "aims to guarantee normal, safe and ordered migration."

Obama is using an administrative rule change to end the policy. Donald Trump could undo that rule after becoming president next week. He has criticized Obama's moves to improve relations with Cuba. But ending a policy that has allowed hundreds of thousands of people to come to the United States without a visa also aligns with Trump's commitment to tough immigration policies.

President Bill Clinton created "wet foot, dry foot" policy in 1995 as a revision of a more liberal immigration policy that allowed Cubans caught at sea to come to the United States become legal residents in a year.

The two governments have been negotiating an end to "wet foot, dry foot" for months and finalized an agreement Thursday. A decades-old U.S. economic embargo, though, remains in place, as does the Cuban Adjustment Act, which lets Cubans become permanent residents a year after legally arriving in the U.S.

Under the terms of the agreement, Cuba has agreed to take back those turned away from the U.S., if the time between their departure from Cuba and the start of deportation hearings in the U.S. is four years or less. Officials said the timeframe is required under a Cuban law enacted after Congress passed the Cuban Adjustment Act.

"For this to work, the Cubans had to agree to take people back," said Ben Rhodes, Obama's deputy national security adviser.

Administration officials called on Congress to repeal the Cuban Adjustment Act.

Officials said the changes would not affect a lottery that allows 20,000 Cubans to come to the U.S. legally each year. But Rhodes cast the shift as a necessary step toward Cuba's economic and political development.

"It's important that Cuba continue to have a young, dynamic population that are clearly serving as agents of change," he said.

Rhodes also cited an uptick in Cuban migration, particularly across the U.S.-Mexico border - an increase many have attributed to an expectation among Cubans that the Obama administration would soon move to end their special immigration status.

Since October 2012, more than 118,000 Cubans have presented themselves at ports of entry along the border, according to statistics published by the Homeland Security Department, including more than 48,000 people who arrived between October 2015 and November 2016.

According to the Pew Research Center, the U.S. saw a spike the number of Cubans entering the country in the first 10 months of 2016 with 46,635 Cubans. That surpassed the fiscap 2015, which had a total of 43,159 Cubans entering the U.S.

Relations between the United States and Cuba were stuck in a Cold War freeze for decades, but Obama and Cuban President Raul Castro established full diplomatic ties and opened embassies in their capitals in 2015. Obama visited Havana last March. Officials from both nations met Thursday in Washington to coordinate efforts to fight human trafficking.

Obama said the Cuban Medical Professional Parole Program, which was started by President George W. Bush in 2006, is also being rescinded. The measure allowed Cuban doctors, nurses and other medical professionals to seek parole in the U.S. while on assignments abroad. The president said those doctors can still apply for asylum at U.S. embassies around the world.

"By providing preferential treatment to Cuban medical personnel, the medical parole program ... risks harming the Cuban people," Obama said.

People already in the United States and in the pipeline under both "wet foot, dry foot" and the medical parole program will be able to continue the process toward getting legal status.

Reaction to the announcement in Havana was muted Thursday afternoon.

"This was bound to happen at some point," said taxi driver Guillermo Britos, 35. "It could impose a more normal dynamic on emigration, so that not so many people die at sea, but it could also take an escape valve away from the government, which was getting hard currency from the emigrants."

Anti-Castro Cubans in Miami were mixed in their responses, with some expressing anger at Obama for what they called another betrayal of ordinary Cubans. Others said they thought the measure would increase pressure for change in Cuba.

"People who can't leave, they could create internal problems for the regime," said Jorge Gutierrez, an 80-year-old veteran of the Bay of Pigs invasion. But he added, "From the humanitarian point of view, it's taking away the possibility of a better future from the people who are struggling in Cuba."

Rep. Illeana Ros-Lehtinen, a Florida Republican who emigrated from Cuba as a child, decried the elimination of the medical parole programs, calling it a "foolhardy concession to a regime that sends its doctors to foreign nations in a modern-day indentured servitude."

Florida Sen. Bill Nelson applauded the administration's decision to abolish the policy.

"The 'wet foot, dry foot' policy was put in place many years ago to help those who were fleeing Castro’s repressive regime. I believe changing this outdated policy in order to be fair to all and also to prevent people from abusing the system is the right thing to do," Sen. Nelson said in a statement.

New Jersey Sen. Bob Menendez, who is Cuban-American, was more critical of the change, and said Congress wasn't consulted about the announcement.

"While more needs to be done to prevent the small universe arriving from Cuba who may seek to exploit the privileges and freedoms that come with the Wet-Foot Dry-Foot policy, those few actors should not destroy our efforts to protect the many who are forced to flee persecution," he said in a statement. "To be sure, today’s announcement will only serve to tighten the noose the Castro regime continues to have around the neck of its own people."

Engage Cuba, an organization that's been working to end the travel and trade embargo on Cuba, praised the change in policy.

"This is a logical, responsible, and important step towards further normalizing relations with Cuba. The 'wet foot, dry foot' policy has been an enduring problem that decades of hostility and isolation failed to solve. This change, which has long had strong bipartisan support, would not have been possible without the re-establishment of diplomatic relations with Cuba," the group said in a statement.