MEXICO CITY — From the moment he took office, President Andrés Manuel López Obrador has studiously avoided a fight with President Trump, gambling that a conciliatory approach would tame the American president.

It certainly has not worked out that way.

When Mr. Trump broke with years of American policy and international practices by forcing asylum seekers to wait in Mexico while their fates are decided, Mr. López Obrador, who campaigned on the promise of defending migrants’ rights, went along with it.

Amid Mr. Trump’s threats to close the American southwest border over illegal immigration, the Mexican authorities cracked down on migrant caravans and accelerated their efforts to detain and deport Central Americans and others trudging north toward the United States.

Yet the warnings from Mr. Trump kept coming.

Now Mr. López Obrador, a lifelong champion of the poor, faces the most concrete threat yet from the American president — a vow to begin imposing tariffs on all Mexican imports in a matter of days.