MEXICO CITY — Until last week, U.S. officials held up El Salvador as proof that foreign aid could help curb migration. The partnership between the two countries drew praise from diplomats, members of Congress and even America’s top border enforcement official.

Then President Trump announced that he was withdrawing economic assistance to the Central American country and its neighbors Guatemala and Honduras.

“They haven’t done a thing for us,” the president said Friday.

The claim baffled development officials and Salvadorans, who saw the country’s cooperation with the United States on security, civil society and economic development as a success story, inasmuch as it achieved the Trump administration’s goal of slowing the flow of migrants heading north to the United States.

In the past three years, both El Salvador’s homicide rate and migration flows have declined sharply. More than 72,000 Salvadorans were apprehended crossing the U.S. border in 2016. By 2018, the number had plummeted by more than half, to fewer than 32,000.

“The decision to cut funding contradicts the results of what we have accomplished together,” Raúl López, El Salvador’s vice minister of justice, said Monday. “The fact is that migration from El Salvador is declining, thanks to our work.”

The United States has spent hundreds of millions of dollars in recent years on programs aimed at bringing stability to one of the world’s most dangerous countries. Money has been spent to train police officers, fund after-school programs and improve local governance.

U.S. officials argued repeatedly that those programs were successful, and they offered the crime and migration statistics that they said proved their claim.

“What [El Salvador is] doing is working, both on the security front and on the economic opportunity front,” U.S. Customs and Border Protection Commissioner Kevin McAleenan said in July.

Trump said he was cutting off aid to El Salvador, Guatemala and Honduras because the countries have failed to curb migration to the United States. He has accused those three countries of allowing their citizens to join migrant caravans destined for the U.S. border.

Analysts have been quick to point out that cutting off assistance to Central America could cause migration to increase, as programs aimed at improving security and economic opportunity are shuttered.

They say the case of El Salvador, a nation of 6.5 million, is still more confounding. Migration from Guatemala and Honduras has surged in the past two years. But in cutting aid to El Salvador, Trump is punishing a government that has overseen a dramatic reduction in migration.

McAleenan, speaking last year at the Bipartisan Policy Center, described El Salvador as a model: “We want to achieve those same successes in Honduras and Guatemala as well.”

The U.S. Embassy in San Salvador did not respond to requests for comment.

Analysts caution against attributing reductions in migration solely to U.S. aid. They say changes in migration are likely the result of a variety of causes, many of them beyond the control of governments.

“There has been no serious look at the historical relationship between development and migration that would convince anyone that economic development of any form across the developing world leads to sudden decreases in migration,” said Michael Clemens, co-director of migration at the Center for Global Development in Washington.“Demographic forces are so much ­stronger.”

Over the last decade, the Salvadoran population aged out of the so-called youth bulge, when a disproportionate number were ages 15 to 29 — the period when people are most likely to migrate.

Guatemala and Honduras are several years behind El Salvador demographically, which might help explain discrepancies in their migration rates.

Migration from the three nations of Central America’s Northern Triangle rose rapidly from 2012 to 2016, much of it undocumented minors fleeing growing gang violence.

According to the Center for Global Development, more than 8 percent of 17-year-olds from El Salvador, Guatemala and Honduras arrived at the U.S. border from 2011 through 2016. In a separate study linking violence to migration, it found that for every 10 additional murders in those three countries, six more children migrated to the United States.

In 2015, El Salvador recorded 103 homicides for every 100,000 residents, more than 20 times the rate in the United States.

In response to the violence and the surge in undocumented minors, the Obama administration launched an aid package for the three countries in 2015 known as the Alliance for Prosperity.

In El Salvador, the aid funded programs to train security personnel, provide jobs to at-risk youth, increase tax collection and a flurry of other projects. Many were aimed specifically at deterring migration, such as assistance for recent deportees, so they wouldn’t attempt to migrate again.

“The truth is that we are really appreciative of these partnerships,” said López, the Salvadoran justice official. “They’ve made a big impact here.

“The question we have now is, “Why would we stop doing something that is working?’ ”

El Salvador is the smallest nation in the Northern Triangle. Its size in relation to Guatemala and Honduras — and the relative strength of its government — make it an easier place to implement development programs, U.S. officials say.

The U.S. government — in speeches, news releases and interviews — emphasized the success of its assistance programs. Between 2015 and 2017, the U.S. Agency for International Development boasted last year, “El Salvador saw a 61 percent reduction [in homicides] in the municipalities in which USAID operates. This compares to a 42 percent reduction nationwide.”

“USAID assistance helps to stem the flow of irregular migration by creating greater economic opportunities for Salvadorans,” the agency said.

Some former U.S. officials agree that it is difficult to control migration through aid. But because most of the Salvadoran migrants were fleeing gang violence and other security problems, they say, there was a clear-cut role for the U.S. government — which it played effectively.

Marcela Escobari was assistant administrator of USAID for Latin America and the Caribbean during the Obama administration.

“U.S. development programs are never going to eliminate migration flows,” she said. “But when there are sudden increases in migration that are attributable to insecurity, we have been able to implement anti-violence programs that have proven to be successful.”

While analysts say cutting aid to El Salvador is likely to contribute to an increase in migration in the long term, the country’s institutions could feel the impact more quickly.

“You might not see the jump from one week to the next,” said Geoff Thale, vice president for programs at the Washington Office on Latin America. “But the impact on program participants and their circles will be real.”

“People will be cut off from alternatives that offer them some hope and some sense that their future in El Salvador will be better,” he said. “Programs that contribute to reducing insecurity by strengthening the rule of law will disappear, and anti-corruption efforts that make investment and economic growth more viable will stall.”

Gabriela Martinez in Mexico City and Nick Miroff in Washington contributed to this report.