Sierra Leone for years had thumbed its nose at U.S. officials, slow-walking deportations so badly that it earned its way onto Homeland Security’s “recalcitrant country” naughty list. Over the last two years of the Obama administration, Sierra Leone took back just 21 deportees.

President Trump took office vowing action, and one of his first executive orders instructed his administration to stop issuing visas to the worst-offending countries. The Sierra Leone government was targeted with sanctions in August 2017, and the change came quickly, with 44 deportees sent back that year, and 79 shipped back in fiscal 2018.

While much of Mr. Trump’s immigration agenda remains tied up in the federal courts or stalemated in Congress, he has made extraordinary progress on recalcitrant countries like Sierra Leone, cutting the number of deadbeat countries from a peak of 23 in 2015 down to just nine as of last month.

The number of countries on the at-risk list, or close to recalcitrant, also has been slashed, from 62 to just 24 as of May.

Long-time deadbeats such as Cuba, China and Vietnam are taking back hundreds more people, even though they remain on the naughty list.

Guinea earned its way off the list by increasing its acceptance of deportees by more than 1,200 percent from 2016 to 2018, while Eritrea went from 13 deportees in Mr. Obama’s final year to 62 last year. Myanmar rose from three to 40.

In fact, only one country on the recalcitrant or at-risk lists did worse last year than in the final year under President Obama, according to a Washington Times analysis of Homeland Security data. The holdout, Ethiopia, accepted 37 deportees in 2016 but just 36 last year. Even it, however, did take back 46 of its deported citizens in 2017.

“Under President Trump, we have made historic progress in ensuring countries take back their nationals who have no legal right to live or work in the United States,” said Katie Waldman, a spokeswoman for Homeland Security.

Visa sanctions are issued by the State Department after notice from the Homeland Security secretary that a country is delaying or denying acceptance of its deportees.

That power has been on the books for years, but had only been used twice — once in 2001 by the Bush administration and once in late 2016 by the Obama administration.

Under Mr. Trump, six countries have already been slapped with deportee-related sanctions.

In each of those cases, the U.S. government said it would no longer issue business or tourist visas to government officials and their families — and warned that even broader sanctions could follow.

That got the attention of diplomats in the target countries, and elsewhere.

“Now these countries understand that the party is over and they — government officials in particular — will face consequences for blocking deportations,” said Jessica Vaughan, policy studies director at the Center for Immigration Studies. “The sanctions work.”

Even still, a massive backlog has built up of people waiting to be deported. China is the worst offender with more than 40,000 in the deportation queue, followed by Cuba with nearly 38,000.

More troubling is that almost all of them have been set free into U.S. communities, thanks to a 2001 Supreme Court ruling limiting detention to just six months in cases when the government doesn’t appear likely to be able to get the other countries to take them back.

That means convicted criminals are often released, including more than 30,000 of the Cubans, nearly 8,000 Vietnamese, nearly 4,000 Laotians and more than 2,000 Chinese.

Ms. Waldman called that a “remarkable public safety risk” that requires action by Congress.

U.S. authorities earlier this year won a five-year sentence against a Ghanaian man who ran a heroin distribution operation from his apartment in National Harbor, in the suburbs outside Washington, D.C.

Jeffrey Okyere had amassed a criminal record and was deported once before, then snuck back in, was caught and served time for that illegal reentry — but Ghana refused to take him back after that, and he had to be released into the community, where he was nabbed after selling thousands of dollars of heroin to an undercover officer.

The Ghanaian government has refused to respond to repeated requests for comment about its decision-making.

In another infamous case, Haiti refused to take back a man who’d served time for attempted murder, insisting it couldn’t verify that he was actually Haitian. The man, Jean Jacques, would go on to kill a young Connecticut woman, Casey Chadwick, after a drug dispute with her boyfriend.

That incident drew the attention of Mr. Trump during the campaign.

In his major immigration policy speech in August 2016, action item No. 7 was insisting that other countries took back their people. He said he would use the visa sanctions tool, and blasted Democratic opponent Hillary Clinton, a former secretary of state who had never used the tool.

He followed through his first week in office, as part of a series of executive orders on immigration that called for ending catch-and-release at the border, clamping down on asylum abuse, punishing sanctuary cities, and hiring more deportation officers and Border Patrol agents.

Each of those has been hindered by the courts or stalled in Congress.

But his demand to use visa sanctions, also tucked inside one of those executive orders, has survived.

Ms. Vaughan said that’s partly because the law is so clearly on Mr. Trump’s side, giving the government explicit powers to withhold visas. If anything, the administration has been limited in only targeting government officials, while the law allows a nation’s entire citizenry to be targeted.

Ms. Vaughan also said the people getting deported are usually high-priority cases, including criminals, perhaps muting some of the antipathy Mr. Trump’s other policies have sparked.

“I suspect that the people deported so far have not been particularly sympathetic cases,” she said.

As for the judiciary, which has blocked some of Mr. Trump’s other immigration moves, it could be tough for anyone to mount a credible legal challenge, she said.

“A time may come when some government official in one of these countries really wants a visa and can’t get it, but those cases are not going to be common, and it’s not easy to win a case involving judicial review of a visa decision,” she said.