The first woman to serve as Mexico’s ambassador to the United States, Martha Bárcena, arrived in Washington in December 2018 at a fraught moment in the two nations’ shared history.

Newly elected Mexican President Andrés Manuel López Obrador, a man with leftist roots, had sent Bárcena to be his envoy to President Donald Trump, who was building a border wall and threatening to torpedo the Mexican economy because he was enraged at a Central American migration surge.

Bárcena spent the next two years in the eye of the Trump storm, helping navigate the finalization of the U.S.-Mexico-Canada Agreement and the implementation of controversial border and migration agreements such as the “Remain in Mexico” policy, which was crafted to placate Trump and deter migrants seeking asylum in the United States.

Bárcena, 63, retired this month after 42 years in Mexico’s foreign service, the last two of which were the most unusual. Trump’s Washington was not a place for traditional diplomacy, and between urgent meetings with White House adviser Jared Kushner, late-night negotiations with Department of Homeland Security officials and the intense interest of Mexican broadcasters in her fashion tastes, Bárcena became part of the show.

“In other embassies, you do foreign policy, bilateral relations, that kind of thing,” she said in an interview. “But the job of the Mexican ambassador in the United States is very different. The relationship with Mexico is managed more at DHS and the White House than the State Department.”

Bárcena said the most difficult moment of her career came in late spring 2019, amid a record influx of Central American families arriving at the southern border that was making Trump furious.

López Obrador had run for Mexico’s presidency telling crowds he wouldn’t do the “dirty work” of immigration enforcement for Washington and hiring well-known human rights figures from the Mexican left, where the defense of migrants was sacrosanct.

But now Trump was threatening to cripple Mexico’s economy with escalating tariffs if López Obrador didn’t crack down on Central American families.

Mexico’s foreign minister rushed to Washington to make amends, and Bárcena joined several rounds of tense negotiations involving Kushner, Vice President Mike Pence, Secretary of State Mike Pompeo and acting homeland security secretary Kevin McAleenan.

Kushner, Trump’s son-in-law, was often the conduit to the president, Bárcena said.

“He helped to smooth out difficulties and sometimes conveyed forcefully to us what was the position of President Trump,” she said.

Mexico agreed to deploy its own national guard troops to stop migrants headed to the United States and to take back tens of thousands of Central Americans seeking asylum in a broad expansion of the Remain in Mexico program, formally known as the Migrant Protection Protocols.

Soon, tent camps spread on the Mexican side, and thousands of parents and children were stranded in dangerous border cities. Migrant rights groups denounced López Obrador’s acquiescence, and critics of the Mexican government — and Bárcena — saw a betrayal.

“That was the most difficult moment of my career,” Bárcena said. “Mexico had been very clear what was our national interest. We were trying to protect our national interests and take measures that were less punishing and less dramatic for the populations involved.”

“Did we manage to do that?” she continued. “Yes, and in some cases, no. In time, we’ll have to evaluate and see — what did we do well and in what did we fail — so we don’t have to repeat that scenario again.”

Bárcena traveled widely during her post and met with Democratic Party leaders, mayors and American executives. Earl Anthony Wayne, a retired career diplomat who served as U.S. ambassador to Mexico under President Barack Obama, said Bárcena “did an exemplary job of walking the line productively between the two governments.”

“She had two presidents who very easily could have had massive differences,” Wayne said. “It’s a culmination for a career diplomat, to use all your experience and wisdom from a lot of years of work, to be able to keep this massive relationship on an even keel and stop it from going in bad directions.”

Bárcena couldn’t stop some elements of the relationship from going sideways. In November, U.S. agents arrested Mexico’s former defense minister, Gen. Salvador Cienfuegos, at the Los Angeles airport, accusing him of working with a drug cartel. He was the highest-ranking Mexican military official to be arrested on drug trafficking charges.

Mexico’s military was outraged, and after López Obrador threatened to curtail narcotics enforcement cooperation with the United States, Cienfuegos was freed, and the charges were dropped, an embarrassment for the Department of Justice. U.S. agents in Mexico have long struggled with cartel corruption of Mexican security agencies and leaks of enforcement plans, but Bárcena said the Mexican government was blindsided by an arrest that came with no warning.

“It was a loss of trust, which is a basis for any cooperation in matters of security and any cooperation,” she said. “We were not informed, at least officially informed, even though (Attorney General William P. Barr) went to Mexico twice. The incident created mistrust and misinterpretation.”

Bárcena said she thinks the Cienfuegos episode should prompt a wider reexamination of the drug war partnership between the two nations.

“Even the term ‘war on drugs’ has been a disaster,” she said. “Measures concentrated on punitive actions have not brought the results expected, so that is one of the issues, when we start talking about the future of security cooperation, that has to be put on the table. What has failed? Why haven’t we reached our objectives?”

Bárcena served as Mexico’s ambassador to Turkey during the Syrian refugee crisis — one of the reasons she was picked to manage the relationship with the Trump administration during a moment of growing tensions over migration. She said she’s optimistic that President Biden and López Obrador can work more productively because they share the goal of promoting investment and job creation in Central America to reduce emigration.

Mexico has 50 consulates in the United States, which serve roughly 40 million Mexican Americans and Mexican nationals, but she said there are still a few things both countries fail to comprehend about their neighbors.

Mexicans, she said, often lack an understanding of how U.S. decisions are made and the limits on the power of the American presidency. “They do not understand the strength of Congress, for example, or of the many decisions taken at the state level. The president of the United States cannot just order a governor to change their decision.”

Similarly, she said, many Americans fail to recognize Mexico’s importance to the United States.

“They think of many other countries as just as important to the U.S., or more important,” she said, “because they do not realize we have been your first or second trading partner, as well as historical links, and family and social links.”

She would like American leaders to engage her country “in a more constructive way,” she said, “instead of trying to lecture Mexico on what to do all the time.”