Mexico’s newly elected president Andrés Manuel López Obrador and his relationship with President Donald Trump could define the future of both countries and have a far-reaching effect on trade, migration, and security cooperation.

The 64-year-old former Mexico City mayor won a landslide victory July 2 after riding a wave of populist anger over government corruption. He is the first leftist elected as president in the country’s democratic history.

Mexico's president-elect Andres Manuel Lopez Obrador reacts as he arrives for a meeting with Confederation of Industrial Chambers (CONCAMIN) in Mexico City, Mexico on July 9, 2018. Alexandre Meneghini / Reuters

He has been compared to Trump for his populist, nationalist rhetoric. In the past, he has been skeptical about the North American Free Trade Agreement (NAFTA).

Many leftists emphasize the negative impacts of the trade deal, which has affected small-scale farmers, lowered environmental standards and made it more difficult to compete against cheaper imports. But in recent months Lopez Obrador has adopted a more positive view of NAFTA and supports reaching an agreement with the U.S. and Canada that tweaks the trade pact. Like Lopez Obrador, Trump has also been critical of NAFTA and regularly threatens to pull out of the agreement arguing that it was not a good deal for American workers.

The United States and Mexico are important trading partners, spending $600 billion annually in trade. About 16 percent of exported U.S. goods go to its southern neighbor, its third largest trading partner. The Mexican economy relies even more on U.S. trade, with about 80 percent of its exports sold here. The U.S. is Mexico's No. 1 trade partner.

The relationship between the two countries has become strained under Trump's watch. The Trump administration has clamped down on illegal immigration and toughened enforcement at border crossings, threatened to scrap NAFTA and sparred with Mexico over Trump’s call for a wall on the U.S.-Mexican border.

The looming question is whether there can be a reset of relations with Mexico's new president, whose six-year term begins December 1. Some experts are not so sure.

“Hopefully they can create a positive working dynamic," said Chris Wilson, deputy director of the Mexico Institute at the Woodrow Wilson Center. "I’m somewhat skeptical they will be able to do that,”

“The underlying tensions in the relationship remain in place, and those are largely coming from the [U.S.] White House,” said Wilson, noting the administration's demands on the renegotiation of NAFTA and its tighter immigration controls regarded by Mexico as violating the human rights of Mexican migrants.

Wilson thinks it will be difficult to resolve these tensions because they are driven by the domestic views and positions that Trump took before he won the 2016 election. “As we enter the 2018 midterm elections, it’s unlikely he will back off on demands on trade and migration issues,” he said.

President Donald Trump makes his way to board Marine One from the South Lawn of the White House in Washington on May 23, 2018. Mandel Ngan / AFP - Getty Images file

Fresh after his victory, López Obrador pledged to “reach an understanding” with Trump.

The NAFTA negotiations are likely to extend into López Obrador’s administration. Coming to an agreement is key for both countries.

There are about 5 million jobs in the U.S. that depend on U.S.-Mexico trade, according to research by the Wilson Center.

A United States Customs agent waits for a northbound truck crossing the border to enter the United States from Nogales, Sonora, Mexico near Nogales, AZ on August 1, 2001. David McNew / Getty Images file

Talks have been stalled over rules of origin for automobiles, which govern what percentage of a car needs to be built in the NAFTA region, as well as over international arbitration panels that resolve commercial disputes, which the U.S. wants to weaken or abolish. Another is the issue of a sunset clause that would allow a member nation to withdraw after five years.

In an interview with the Televisa news network, López Obrador said, “We are not going to fight. We are always going to seek for there to be an agreement … We are going to extend our frank hand to seek a relation of friendship, I repeat, of cooperation with the United States."

NAFTA's collapse would extend beyond trade

Renegotiating NAFTA could have profound effects that go beyond its economic impact. Although Mexico relies heavily on its northern neighbor for trade and investment, its contributions to the U.S. are significant, especially in the areas of migration and security cooperation.

Houses are seen on the Mexican side of the US/Mexico border fence in Jacumba, California on on April 6, 2018. Sandy Huffaker / AFP - Getty Images file

If the U.S. withdraws from the trade agreement, it could make it difficult for the Mexican government to collaborate in those areas.

In recent years, immigration patterns have changed drastically. Mexican migration to the U.S. has decreased and more Mexicans are leaving the U.S. than entering it.

Meanwhile, Mexico has become a transit route for hundreds of thousands of Central American migrants. A record number of Salvadorans, Hondurans, and Guatemalans are fleeing gang violence and a lack of economic opportunities in their home countries. While in the past, Mexican officials allowed migrants to pass through their territory, now under U.S. pressure, Mexican authorities have been cracking down on the migrants and deporting them.

“Finding ways to continue to have Mexico as a partner in immigration issues is very important for the U.S. But in order to do so, there needs to be a broadly positive tone in the relationship,” Wilson said.

A deterioration of relations could also impact security cooperation. During the past two decades, as their economies have become interdependent, the two nations have developed a greater level of collaboration in dealing with terrorist threats and capturing criminals. If relations sour, the incentives for the Mexican government to continue cooperating could diminish.

“I think López Obrador will be much less accommodating to Trump’s abrasive comments about Mexico and Mexicans," said Michael Shifter, president of the Inter-American Dialogue, an international affairs think tank.

“I think he would be prepared to revisit security cooperation with the U.S.,” he added.

Newly elected President of Mexico, Andres Manuel Lopez Obrador, speaks during a press conference after a private meeting with Outgoing President Enrique Pe?a Nieto as part of the government transition at Palacio Nacional in Mexico City, Mexico on July 3, 2018. Manuel Velasquez / Getty Images

The relationship will be a delicate balancing act for López Obrador. Many Mexicans remember statements made by Trump at the beginning of his presidential campaign saying Mexico is sending rapists, murderers and people carrying drugs to the U.S. There is immense pressure on López Obrador to be tough on this kind of rhetoric. Mexico President Enrique Peña Nieto took a lot of heat when he hosted candidate Trump on a visit to Mexico.

Some fear that if bilateral ties worsen, Mexico could cut back on extraditing criminals, for instance. It can also stop helping on issues like fighting poppy cultivation, which are the plants used to make heroin. Over 90 percent of heroin in the U.S. comes from Mexico.

In the end, the relationship will hinge on whether the Trump administration pursues policies that Mexico sees as harmful and on how López Obrador responds.

“At the beginning of an administration there is always an opportunity,” Shifter said. “Right now López Obrador has enormous political capital and popularity. He seems to be showing signs of moderation and pragmatism. I think there is a chance that relations can be reset in a positive way.”

FOLLOW NBC LATINO ON FACEBOOK, TWITTER AND INSTAGRAM.