MEXICO CITY — The four candidates to be president of Mexico called each other liars and hypocrites. They slung demeaning nicknames. They lobbed accusations about each other’s alleged corruption and pampered families.

But if there was one thing that the candidates agreed on in a debate Sunday night, it was President Trump.

The candidates charted a similar course: Each said he would demand respect from Trump, who has called for a giant border wall, accused Mexico of doing little about illegal migration and demanded a renegotiation of NAFTA. At the same time, the candidates all said they wanted a positive relationship with the United States.

Trump looms over this election in a way that has few parallels in recent U.S.-Mexico history. Much of Sunday night’s debate, the second of three before the July 1 vote, probed how the candidates would respond to what one of the moderators described as the “Trumpian threat.”

Still, analysts predict that Trump may not end up being a defining issue in the election or one that separates the candidates.

“They all say the same thing: No one likes Trump’s discourse, but the United States is a neighboring country and you have to negotiate with its government,” said Raul Benitez Manaut, an expert on U.S.-Mexico relations at the National Autonomous University of Mexico. “Nobody wants a fight with Donald Trump.”

Trump was the backdrop to the two-hour debate in Tijuana, which focused on trade, migration and cross-border security issues.

At one point, candidate Ricardo Anaya held up a large photo of Trump, then a candidate, on a 2016 visit to Mexico to meet President Enrique Peña Nieto.

“The problem began on this day,” Anaya said, recalling how Peña Nieto invited the American politician to visit, in what turned out to be a deeply unpopular gesture. Anaya said the move was “not only an error, it was a humiliation for the Mexican people.”

Andrés Manuel López Obrador, a leftist candidate who is the front-runner in the election, declared: “Trump is going to have to learn to respect us. That I can guarantee you.”

The most fiery response to Trump’s policies came from Anaya, 39, who is the candidate of a coalition of left- and right-leaning parties. He has established himself as López Obrador’s main challenger, polling ahead of José Antonio Meade, the candidate of the ruling Institutional Revolutionary Party.

“You can’t appease tyrants and bullies. You have to confront them,” Anaya said.

He said he would reexamine all aspects of the bilateral relationship, including cooperation on security and immigration, to give Mexico more leverage in dealing with the White House. He also called for more generous immigration policies in Mexico for Central Americans fleeing violence, most of whom transit the country for entry to the United States, and urged more cooperation with the migrants’ governments.

“We’re not going to have moral authority to demand that the United States respects our migrants, if we don’t respect our Central American brothers who are entering our country,” Anaya said. “One peso invested in cooperation is worth much more than a peso invested in an absurd wall, like the one Donald Trump wants to build.”

Meade, the former finance and foreign minister, promised to defend Mexico’s dignity.

“I’m not going to permit, under any circumstances, that they fail to show us respect,” he said. “Never.”

But these candidates offered little detail about what a new Mexican strategy might look like. There is widespread agreement among the candidates — including López Obrador, considered the most protectionist — about the benefits of the North American Free Trade Agreement, and all want the current negotiations to lead to a new version of the pact.

“The proposals were vague, the candidates were elusive in their answers,” said Jorge Chabat, a professor of international relations at CIDE, a research university in Mexico City. “It seems like no one had a very clear idea what to do with the United States.”

Trump is deeply unpopular in Mexico and his policies could have a powerful impact on the country, given that the United States is its No. 1 trading partner. But so far, the Mexican presidential campaign has been dominated by domestic issues like corruption and slow economic growth.

López Obrador, 64, who has lost two elections, vows to clean up corruption and pay more attention to Mexico’s rural poor. He has maintained a strong advantage in recent polls, leading by as much as 20 points. His candidacy has worried some in Mexico’s business community who are concerned that he might roll back recent changes, including the opening of Mexico’s oil industry to private investment.

López Obrador has a reputation as a forceful and combative speaker, but during the campaign he has focused his ire almost entirely on Mexico’s ruling elite, which he considers a corrupt and insular “mafia” that does not govern for the poor.

“If they threaten us with building walls, with militarizing the border, with persecuting our countrymen, what we need to do is strengthen our economy so that there is work in Mexico so that people don’t need to migrate,” López Obrador said during the debate.

Asked about booming opium poppy production in Mexico, which feeds the U.S. heroin market, López Obrador said he wanted to push crop-substitution programs and get poppy farmers in Mexico to switch to growing corn. In response to the same question, Anaya said the United States has done nothing to stop guns flowing into Mexico and he wanted to press the Trump administration to address this issue. Violence has soared in Mexico as armed groups fight to control parts of the poppy trade.

The final debate is scheduled for June 12.

Gabriela Martinez contributed to this report.