The type of migration has changed significantly since then. In the early 2000s, many Mexicans headed north to work in industries, such as construction, that boomed before the financial crisis. Today, the numbers are being elevated by Central Americans, among them many small children and people fleeing violence. More than 84,000 of the 132,887 people apprehended for crossing the border illegally in May were captured with family members, while 11,500 were unaccompanied minors.

There are various forces driving families from their homes in Honduras, El Salvador, Guatemala and Nicaragua, including poverty, drought and corrupt authoritarian governments. But what really devastates communities is gang violence. This is not only a question of homicides but also of predatory crimes, including extortion, kidnapping and rape, that cause victims such as Ms. López to run for their lives without money or solid plans.

Interviewing dozens of migrants coming through Mexico in recent months, I heard time and time again of brutality that makes them flee despite the terrible conditions on the road. That’s why Ms. López was risking the perilous freight trains with her young children.

Mexico has been stumbling in its response to this northward migration. After President Andrés Manuel López Obrador took power in December, he promised humanitarian visas and work for those who came, but then he shifted to mass detentions and deportations. In April, Mexico arrested more than 20,000 undocumented migrants, double the number in February. Under the new agreement, it will try to detain many more.

But Mexico may not be willing or able to sustain such a crackdown over years, while the root problems in Central America rage on. More aid to communities, especially for independent organizations that work to stop violence and protect the vulnerable, would be more likely to prevent people fleeing. And it would be cheaper than detaining refugees in wretched conditions.

Putting tariffs on Mexican goods is the worst solution of all. Over the last two decades, Mexico’s economy has become interdependent with the United States’; there was more than $600 billion in cross-border commerce last year. But now it is stuck with a trade partner that can threaten tariffs over nontrade issues at any time.

If Mexico were pushed into recession, it would be even less equipped to deal with the flows of migrants and refugees. Economic downturn could push even more people into crime and weaken the government’s efforts to contain sprawling drug cartels.

President Trump mistakenly believes that America can become stronger through threats and bullying. But the poorer and more unstable it becomes south of the Rio Grande, the bigger the problem for the United States.

Ioan Grillo (@ioangrillo) is the author of “Gangster Warlords: Drug Dollars, Killing Fields, and the New Politics of Latin America” and a contributing opinion writer.

The Times is committed to publishing a diversity of letters to the editor. We’d like to hear what you think about this or any of our articles. Here are some tips. And here’s our email: letters@nytimes.com.

Follow The New York Times Opinion section on Facebook, Twitter (@NYTopinion) and Instagram.