Then-candidate Donald Trump walks with Mexican President Enrique Peña Nieto. (Dario Lopez-Mills/Associated Press)

There has been much focus on President Trump’s erratic foreign policy — the outlandish positions, the many flip-flops, the mistakes. But far more damaging in the long run might be what some have termed the Trump effect: his impact on the domestic politics of other countries. That effect appears to be powerful, negative and enduring. It could undermine decades of U.S. foreign policy successes.

Look at Mexico. For generations, this was a country defined by fiery anti-Americanism. Founded by a radical revolutionary movement, fueled by anger against U.S. imperialism and high-handedness, Mexico would rarely cooperate with Washington. Since the 1990s, the landscape has shifted, indeed almost reversed. Thanks to intelligent leadership in Mexico City and consistent bipartisan engagement by Washington, the United States and Mexico have become friendly neighbors, active trading partners and allies in national security.

Mexico buys more U.S. goods than China and is, in fact, the second-largest destination for U.S. exports, after Canada. Sales to Mexico are up 455 percent since the passage of NAFTA. The country cooperates with the United States on border security, helping to interdict drug shipments and deporting tens of thousands of Central American migrants who aim to enter the United States illegally. Mexico is an ally of the United States in most international negotiations and organizations.

All of this could change easily. Over the past year, as Trump has attacked and demeaned Mexico and its people, the political landscape there has shifted. President Enrique Peña Nieto’s already declining approval ratings plummeted after he was seen as too conciliatory toward Trump. It is now quite possible — in fact, likely — that the next president of Mexico will be an anti-American socialist-populist similar to Venezuela’s Hugo Chávez. Andrés Manuel López Obrador was polling at about 10 percent at the start of 2015. He is now at about 30 percent, the front-runner among the potential candidates in next year’s election.

A victory for López Obrador would be a disaster for Mexico — but also for the United States. It would likely take Mexico back to its days of corrupt socialism and dysfunctional economics, all sustained by populism and nationalism. López Obrador has described Trump as a “neo-fascist,” attacked the Peña Nieto administration for being too weak to confront Trump and promised to get tough with Washington. In February, he began a tour of U.S. cities, speaking at large rallies of Mexican Americans and symbolically standing up to Trump.

(Alice Li/The Washington Post)

Now consider South Korea. Trump’s demand that Seoul pay for the THAAD missile defense system, threatening to overturn the existing agreement with Washington, has fueled the forces in South Korea that oppose that system in the first place, along with any aggressive military measures against North Korea. Trump has casually delivered a number of slights to one of the United States’ closest allies, accepting wholesale China’s claim that Korea once belonged to it and threatening to tear up the U.S.-South Korea free-trade agreement. South Korea is facing a snap election for its presidency, and the candidate who is benefiting most from Trump’s antics is the left-wing Moon Jae-in. Anti-Americanism has returned to South Korea in force, though not quite as strongly as in Mexico, where Trump’s favorability has been recorded at 3 percent.

Were these trend lines to harden, it could mean decades of difficulty for U.S. foreign policy. Dealing with North Korea is hard enough as it is, but with a recalcitrant South Korea that is determined not to be viewed as overly pro-American, it would become impossible. Tackling issues of drugs, border control and migration would become much harder if the Mexican government recoiled from cooperating with the United States.

There are other places where the Trump effect is also clear. Politics in Iran have become more favorable to hard-liners, and the reelection of the relatively moderate President Hassan Rouhani, once seemingly assured, is now in jeopardy. Supreme Leader Ayatollah Ali Khamenei appears to be campaigning against him and supporting a far more anti-U.S. candidate. In Cuba, Raúl Castro has gone from inching toward better relations with the United States to lambasting Trump and his policies. Around the world, the United States’ friends are embarrassed and on the defensive, and its enemies are gloating.

In foreign policy, great statesmen always keep in mind one crucial reality: Every country has its own domestic politics. Crude rhetoric, outlandish demands, poorly thought-through policies and cheap shots all place foreign leaders in a box. They can’t be perceived as surrendering to the United States, and certainly not to a nation led by someone who is determined to show that for the United States to win, others must lose. That’s one big difference, among many, between doing a real estate deal and managing foreign policy.

Read more from Fareed Zakaria’s archive, follow him on Twitter or subscribe to his updates on Facebook.