A sign at the U.S.-Mexico border in Santa Teresa, N.M. (Luke Sharrett/Bloomberg)

PRESIDENT TRUMP has a good idea of the power the United States wields over Mexico, and the pain it may inflict — the construction of a wall Mexico fiercely opposes; taxes that could be slapped on Mexican imports, wreaking havoc on its economy; deportations of undocumented Mexican immigrants living in the United States, who would be thrust back into a country that would struggle to absorb them. Mr. Trump might have a fuzzier idea of the pain Mexico, its people furious and its pride wounded by his taunts and contempt, might inflict on the United States.

Start with those deportations. At least half of America’s 11 million unauthorized immigrants are Mexican, but many have no documents proving their nationality. For the Trump administration to deport them, it would need cooperation from Mexico, which cannot be forced to accept deportees without certifying that they are Mexicans. As former Mexican foreign minister Jorge G. Castañeda has already warned, Mr. Trump can round up hundreds of thousands or millions of migrants, but without Mexico’s cooperation, they could clog U.S. detention centers and immigration courts — at enormous cost and, conceivably, for years.

Consider, too, the effect on America’s southern border if Mexico were to loosen immigration controls on its own southern border — the one over which Central American refugees are already streaming north in near-record numbers. Even with what U.S. officials say are aggressive interdiction efforts by Mexican authorities, the Border Patrol detained more than 220,000 mainly Guatemalans, Hondurans and Salvadorans crossing from Mexico into the United States in the fiscal year ending last fall, exceeding the number of Mexicans apprehended, which has fallen to a 45-year low. If you think the Border Patrol is swamped now, as Homeland Security Secretary John F. Kelly insists, imagine if Mexico, which last year sent home more than 140,000 Central Americans, simply stepped aside.

U.S. and Mexican officials work closely on an array of other bilateral concerns, from drug trafficking and organized crime to human smuggling and antiterrorism programs. Privately, U.S. officials may grouse that their counterparts aren’t always paragons of efficiency; they also acknowledge that, without Mexico’s help, combating crime and controlling the border would be infinitely more difficult.

In launching his presidential campaign, Mr. Trump called Mexicans rapists, and he has taunted the Mexican government at every turn. Those displays of public humiliation are not constructive elements in diplomacy; they may easily come back to haunt Washington. Already, his disdain has inflamed Mexican popular opinion, improving the prospects of Mexico’s anti-American left in next year’s presidential elections.

Mr. Kelly, who as a Marine led U.S. Southern Command, said in his confirmation hearing that partnerships “as far south as Peru” are more important to U.S. border security than building a wall. Along with Secretary of State Rex Tillerson, he headed to Mexico on Wednesday, just after the Department of Homeland Security released its new deportation guidelines. If the goal was to widen bilateral cooperation and soothe the harsh feelings Mr. Trump has engendered with our neighbor and ally, the timing was pitiable.