MEXICO CITY — After years of bending to the demands of the Trump administration, including dispatching agents to block the flow of migrants, Mexico's president had a request of his own. He wanted Gen. Salvador Cienfuegos Zepeda, a former Mexican defense minister charged by the United States with drug trafficking, returned to Mexico.

On Wednesday, President ­Andrés Manuel López Obrador got his way, welcoming the decision of a federal judge to drop the charges in one of the Justice Department's biggest drug-
trafficking cases in recent history, clearing the path for Cienfuegos's release to Mexico as a free man.

López Obrador's critics have accused him of repeatedly making compromises with the United States but getting little in return. On Wednesday, though, he showed the fruit of his efforts.

"We acted from principle," he told reporters. "What was done in this case was to intervene in political and diplomatic matters, to express our disagreement."

But the dramatic reversal did not resolve a deeper tension that has crept into bilateral relations since Cienfuegos's arrest in Los Angeles last month. Mexican officials were incensed to learn that U.S. prosecutors had been investigating Cienfuegos for years without informing them. They learned of the probe only after his arrest — a scandal here that prompted official threats to limit future cooperation with the United States, including restrictions on the U.S. Drug Enforcement Administration's work in Mexico.

Negotiations between the two governments continued as López Obrador was conspicuous as one of few world leaders not to congratulate President-elect Joe Biden on his election victory. Mexican Foreign Minister Marcelo Ebrard said there was no connection between the negotiations and López Obrador's silence on the U.S. election.

Even after Cienfuegos returns to Mexico, current and former U.S. and Mexican officials say, the security relationship will need work. Ebrard said "respecting the sovereignty of Mexico" must be fundamental to the partnership.

A separate division, meanwhile, has emerged within the U.S. government. Current and former law enforcement officials expressed frustration that such an important case was spiked.

"For any agent, intelligence analyst, prosecutor to build an investigation and apprehend a subject, especially of this level, just to have your work dismissed and the subject accentually set free, I would think feelings of demoralization is an understatement," said Carl Pike, the former assistant special agent in charge of the DEA's Special Operations Division for the Americas.

Prosecutors insisted in court Wednesday that their case against Cienfuegos was strong; they said they were seeking dismissal to preserve the delicate relationship between the two countries.

The deal was announced Tuesday evening by Attorney General William P. Barr and Alejandro Gertz Manero, his Mexican counterpart. Prosecutors asked that the case be dismissed in such a way that it could be filed again.

In a federal courtroom in New York on Wednesday, Judge Carol Bagley Amon asked Cienfuegos if he agreed to “voluntarily depart the United States expeditiously in the custody of the United States marshals.”

“Si, señora,” he responded. It was unclear whether he would be detained on arrival in Mexico. His lawyers believed he would be at liberty, able to reunite with his family.

Around 9 p.m. EST, prosecutors filed confirmation that the Marshals “successfully transported the defendant to Mexico.”

Amon had just one substantive question about prosecutors’ decision to seek dismissal: Was the call made by Barr? Acting U.S. attorney Seth DuCharme confirmed that it had been.

The Justice Department spent years investigating Cienfuegos, who served as Mexico’s top defense official from 2012 to 2018 under then-President Enrique Peña Nieto. Prosecutors said they discovered thousands of exchanges that showed that he was also working with the H-2 cartel to expand its territory and move drugs into the United States. Cienfuegos pleaded not guilty this month.

It appeared to be a blockbuster case, revealing deep connections between the Mexican state and the country’s criminal underworld. Amon called the decision to dismiss it “a matter of foreign policy.”

Mexico has agreed to use U.S. evidence in an investigation against Cienfuegos but has not committed to putting him on trial.

For years, U.S. officials have criticized the weakness of Mexico’s criminal justice system, where powerful actors are rarely held to account. On Wednesday, López Obrador appeared to cast doubt on the evidence against Cienfuegos.

“There is no impunity for anyone, but at the same time crimes will not be allowed to be fabricated,” he said. “There must be support, evidence — no person can be the victim of an injustice.”

A lack of faith in Mexican courts is one of the main reasons so many major drug traffickers are brought to trial in the United States.

“The very fact of Cienfuegos’s arrest in the United States is a product of a lack of U.S. confidence in Mexico’s ability to hold individuals like him accountable,” said David Shirk, a political scientist who studies Mexico’s justice system at the University of San Diego.

Amon expressed confidence that Mexico would move forward with its case against Cienfuegos.

“I have no reason to doubt the government’s determination that the Mexican prosecuting authorities sincerely wish to pursue an investigation and prosecution of this defendant,” the judge said.

Amon said she credited the word of Justice Department officials that Mexico was prepared to move forward with a case against Cienfuegos.

López Obrador has described the investigation and arrest of Cienfuegos as a violation of Mexican sovereignty. The Mexican military, revered by much of the country, is a crucial piece of his security strategy. In securing Cienfuegos’s return to Mexico, López Obrador said he was defending the country’s honor.

“What is involved here is the prestige of a fundamental institution of the Mexican state, which is the Secretariat of Defense, the armed forces, and it is not just anything,” he said. “We cannot allow without evidence the undermining of our fundamental institutions.”

For decades, the country’s armed forces have seemed largely exempt from scrutiny, an institution considered untouchable across administrations and political parties. The decision to drop the charges against Cienfuegos appeared to reinforce that idea.

The Mexican military’s “power has only increased since AMLO came to power and started relying on the military for civilian tasks,” said Esteban Illades, the editor of Nexos magazine, referring to López Obrador. “What Cienfuegos’s return to Mexico shows is that the president answers to the army and not the other way round.”

Eruviel Ávila, the Mexican senator who heads the Senate’s commission on the marines, tweeted that the decision “is a recognition to all the Armed Forces of our country.”

Cienfuegos’s legal team was emphatic that his return was not contingent on Mexico actually bringing a case against him.

“The Mexican government is in no way required to commence an investigation or prosecution of Gen. Cienfuegos,” attorney Edward Sapone told The Washington Post. “If we pay attention to the language of the agreement to dismiss, it clearly states that the Mexican government may investigate, but it is not required to.”

Publicly, prosecutors continued to express confidence in the charges. “The office stands behind the case,” DuCharme said. “There’s no concern that I have with the strength of our case.”

This move, he said, is about a “balance between the department’s interest in pursuing the prosecution against the interests of the United States in foreign relations.”

Cienfuegos was expected to be ushered to an airport in the custody of U.S. marshals, but it was unclear where he was ultimately headed.

“His first priority is to reunite with his family, whom he loves and misses dearly,” attorney Raymond Granger said. “He’ll continue, as he has done since the moment of his arrest, to assert his innocence vigorously. He hopes the Mexican government will continue to do the right thing and ultimately conclude that no charges are warranted.”

Jacobs reported from New York. Devlin Barrett in Washington contributed to this report.