No one ever accused Donald Trump of strategic thinking. He prefers to watch the cable news shows and, when he is sufficiently riled up, react accordingly, usually blurting retaliatory bile on Twitter, always with an eye on his core supporters and rarely on longer-term considerations.

Take last Sunday. Fox News aired an interview with a leader of one of the Border Patrol’s unions complaining about obstacles his members allegedly face keeping illegal immigrants from entering the country. The segment had been spurred by reports of a 1,200-strong “caravan” of Central American migrants, mostly Hondurans, trudging northwards through Mexico, supposedly in hopes of reaching the US border. Before you could say rapists and criminals, Trump was on Twitter urging Republicans to rewrite the rules of the Senate “to pass tough laws now”.

The outburst presaged a multi-day tizzy-fit from Trump that veered quickly into Mexico-bashing. He threatened to end the North American Free Trade Agreement (Nafta), already being renegotiated, unless Mexico acted to stop the caravan’s progress. He said he had lost interest in helping protect the roughly 800,000 ‘Dreamers’, brought to the US illegally by their parents when they were kids. Then he announced plans to reinforce the Border Patrol with National Guard troops.

An irked President Enrique Pena Nieto, inferred that Trump was really just in a sulk because he didn’t get his way persuading the US Congress (or his own government) to pay for his vaunted wall. “If your recent declarations are due to frustration over issues to do with internal policy, your laws, or your Congress, direct yourself to them, not to Mexicans,” Pena Nieto said.

Regardless of sheer good-neighbourliness, it is hardly wise for a US president to seek to destabilise the government of Mexico, in particular if hardening the border is your main concern. A wounded Mexico means less effective immigration control, more drug trafficking and a renewed impetus for its citizenry to migrate north in search of a safer, less impoverished life.

Still, one man is as happy as a sandboy, and this is where Trump is making his gravest miscalculation. His name is Andres Manuel Lopez Obrador. You may remember him. (Mexicans call him AMLO.) He is the leftist firebrand who in 2006 was defeated in that year’s presidential elections by Felipe Calderon by a margin of 0.58 per cent. So sure was he that he had been cheated of victory, he had his supporters set up camp in the historic downtown district of Mexico City, paralysing it for months.

Lopez Obrador is running again and he might win. Latest polling gives him an 18 per cent lead over his main rivals, including Jose Antonio Meade of the ruling PRI party. It is a prospect that should make Washington tremble. The leader of the nascent National Regeneration Movement, Morena, he would be no Hugo Chavez, but under his rule, Mexico, a more or less fully paid-up member now of the club of free-market economies, would be tugged sharply to the left.

He has, for example, already promised to adopt a harder line than Pena Nieto on Nafta which he believes has failed to lift Mexican workers to the extent that was promised. He has threatened to reverse recent energy sector reforms that after years of protectionism are opening Mexico’s oil reserves and refineries to foreign (mostly US) investment. He even talks of halting construction of the capital’s spanking new international airport where ground is already broken.

It didn’t go unnoticed that Lopez Obrador chose the border city of Ciudad Juarez to launch his campaign last weekend. It is on the border, just across from El Paso, Texas, and named for Benito Juarez, a 19th-century Mexican president and the country’s most potent national hero. It is not just as a leftist that he hopes to seize the presidency on 1 July, promising relief to Mexico’s poor, but also as the last true defender of the country’s sovereignty under siege more than ever before by an increasingly unfriendly and bellicose neighbour to the north.

You begin to see how Trump is playing directly into Lopez Obrador’s hands. To many Mexicans, the deployment of troops to the border is the last straw in a long run of antagonistic acts by the US, tantamount even to an actual declaration of war. Be sure that Lopez Obrador, who led the municipal government of Mexico City in the early 2000s, won’t miss the chance to stir up an even greater wave of anti-Trump sentiment and further boost his chances of victory.

He was at it even in Ciudad Juarez, invoking a favourite symbol of Mexican culture to lash out at the current Oval Office occupant. “Mexico and its people will not be the pinata of any foreign government,“ he declared at a launch rally attended by thousands who erupted in jeers at the mere mention of Trump. “It’s not with walls or use of force that you resolve social problems.”