MEXICO CITY (Reuters) - Donald Trump’s habit of slapping down Mexico is feeding nationalist sentiment in the country’s presidential election campaign, prompting contenders to defy him and strengthening the hand of the frontrunner, who is courting the anti-establishment vote.

FILE PHOTO: Mexican presidential candidate Andres Manuel Lopez Obrador of the National Regeneration Movement (MORENA) speaks during the presentation of his shadow cabinet for the July 2018 presidential election, in Mexico City, Mexico December 14, 2017. REUTERS/Edgard Garrido/File Photo

In the past week, the three top contenders for the July election have all said Mexico will not pay for the wall the U.S. president wants to build on the U.S. southern border. None has made the point more forcefully than Andres Manuel Lopez Obrador, a veteran leftist leading the opinion polls.

A victory for Lopez Obrador, who was runner-up in 2006 and 2012, could usher in a more distant and confrontational relationship between the two nations as he promises to lessen Mexico’s economic dependence on foreign powers.

That dependence is strongest with the United States: Mexico sends about 80 percent of its exports to its northern neighbor and the United States has traditionally been the source of the bulk of foreign direct investment. Under Trump, however, Mexican views of the United States have soured.

“Without being disrespectful, we’re going to put him in his place,” Lopez Obrador said of Trump on Thursday in the Gulf of Mexico port of Veracruz, the scene of a notorious national humiliation when U.S. forces occupied it in 1914.

Earlier that day, Trump told his Twitter followers that Mexico was “rated the number one most dangerous country in the world.” Although violence is rising in Mexico, its murder rate remains well below that of several Latin American countries, data compiled by the United Nations and the World Bank show.

Lopez Obrador, who said earlier this month he would put an end to what he called puppet governments in Mexico taking instructions “from abroad,” promised to hit back against Trump’s barbs and tell the American “what I think” on Twitter.

A December survey by polling firm Parametria gave Lopez Obrador an 11 percentage point lead, while another last week by Mitofsky gave him a three point advantage, but growing.

Since taking office a year ago, Trump has often expressed negative views of Mexico, blaming it for drugs entering the United States, criticizing U.S. companies with operations south of the border, and insisting Mexico will pay for the wall he wants to stop illegal immigration. He has threatened to tie payment to the terms under which the two neighbors trade by reworking or canceling the North American Free Trade Agreement (NAFTA).

Slideshow ( 2 images )

Each time, President Enrique Pena Nieto’s government has pushed back.

This week presidential hopeful Ricardo Anaya of the conservative National Action Party (PAN), who heads a left-right coalition, and the ruling Institutional Revolutionary Party’s (PRI) contender, Jose Antonio Meade, also weighed in.

“Mexico will NOT under any circumstances pay for that wall,” Meade said on Twitter on the day Lopez Obrador was in Veracruz.

Few issues unite Mexicans more than dislike of Trump, who kicked off his presidential bid in 2015 by accusing the country of sending rapists and drug runners across the U.S. border.

Jorge Buendia of pollster Buendia & Laredo said Trump had made it advantageous for Mexican politicians to criticize him, and that it would be “very costly” for the next president to extend the hand of friendship towards his government.

“So it’s only a matter of time before there are much more critical proposals about Trump and U.S. relations,” he said.

The most obvious beneficiary of opposition to Trump, at least initially, would be Lopez Obrador, Buendia said.

‘ANGER AMONG MEXICANS’

A study published last week featuring data from the Pew Research Center and Buendia & Laredo showed that since Trump entered presidential politics, the image of the United States has deteriorated sharply in Mexico.

In 2015, 66 percent of Mexicans held a favorable view of the United States and 29 percent an unfavorable opinion, it showed. By October 2017, 65 percent of Mexicans had an unfavorable view of the United States and only 30 percent a positive one.

Heriberto Galindo, a former PRI congressman and ex-consul general of Mexico in Chicago, said Trump would end up unifying the rhetoric of all the presidential candidates against him.

“I’m not saying we’re heading for war with the United States, because Mexico is pacifist,” he said. “But President Donald Trump is causing a lot of anger among Mexicans ... and a negative attitude towards the United States, which is not helpful, beneficial or healthy, least of all with a neighboring country.”

Anti-Trump feeling is only likely to intensify if the president follows through on threats to dump NAFTA, which underpins much of Mexico’s trade, if it is not reworked to better favor U.S. interests. Negotiators hold another round of talks this week to try to overhaul the deal.

Agustin Barrios Gomez, a former federal congressman and head of Fundacion Imagen Mexico, a group dedicated to promoting Mexico’s image abroad, argued Lopez Obrador does not even need to sharpen his rhetoric to benefit from Trump, because he has no credible rivals to oppose his nationalist arguments.

Both Meade and Anaya represent parties that defended closer economic integration and cooperation with the United States and are the only ones to have held power, Barrios Gomez noted.

Now Trump’s hostility has shattered that model, he added.

“The feeling’s there: you trusted these guys (the United States), and they turned on you like the left have been saying for God knows how long,” he said. “And that plays to Andres Manuel’s strengths because he doesn’t have to say anything.”