Donald Trump, then a Republican presidential candidate, at a news conference with Mexican President Enrique Peña Nieto in Mexico City on Aug. 31, 2016. (Dario Lopez-Mills/AP)

Tentative plans for Mexican President Enrique Peña Nieto to make his first visit to the White House to meet with President Trump were scuttled this week after a testy call between the two leaders ended in an impasse over Trump’s promised border wall, according to U.S. and Mexican officials.

Peña Nieto was eyeing an official trip to Washington this month or in March, but both countries agreed to call off the plan after Trump would not agree to publicly affirm Mexico’s position that it would not fund construction of a border wall that the Mexican people widely consider offensive, said the officials, who spoke on the condition of anonymity to discuss a confidential conversation.

Speaking by phone on Tuesday, Peña Nieto and Trump devoted a considerable portion of their roughly 50 minute conversation to the wall, and neither man would compromise his position.

One Mexican official said Trump “lost his temper.” But U.S. officials described him instead as being frustrated and exasperated, saying Trump believed it was unreasonable for Peña Nieto to expect him to back off his crowd-pleasing campaign promise of forcing Mexico to pay for the wall.

Both accounts confirm it was Peña Nieto’s desire to avoid public embarrassment — and Trump’s unwillingness to provide that assurance — that proved to be the dealbreaker.

A physically slight man, Peña Nieto has been loath to put himself in an environment in which the more imposing Trump could play the bully. Peña Nieto’s style is exceedingly formal, and he is averse to verbal combat, making his carefully scripted public events the opposite of Trump’s often freewheeling appearances.

With Mexico heading into a July presidential election, any action by Peña Nieto that could be seen as kowtowing to Trump or buckling under U.S. pressure risks damaging the prospects for his Institutional Revolutionary Party.

The two presidents’ public posturing over the wall — Trump demands that Mexico pay for it; Peña Nieto insists that it will not — has harmed their personal relationship and jeopardized the alliance between their neighboring countries.

“The problem is that President Trump has painted himself, President Peña Nieto and the bilateral relationship into a corner,” said Arturo Sarukhan, a former Mexican ambassador to the United States. “Even from the get-go, the idea of Mexico paying for the wall was never going to fly. His relationship with Mexico isn’t strategically driven. It’s not even business; it’s personal, driven by motivations and triggers, and that’s a huge problem. It could end up with the U.S. asking itself, ‘Who lost Mexico?’ ”

Still, negotiations between their respective administrations continue apace on the North American Free Trade Agreement and other issues. And both governments have strived to portray their ties as strong and the exchanges between their leaders as smooth.

“We enjoy a great relationship with Mexico and the two administrations have been working for a year to deepen our cooperation across a range of issues including security, immigration, trade and economics,” Michael Anton, the top spokesman for Trump’s National Security Council, said in a statement.

Mexican Foreign Secretary Luis Videgaray called the U.S.-Mexico relationship closer under Trump than in previous administrations.

“I think in many ways the relationship today is more fluid,” Videgaray said earlier this month in Mexico City alongside Secretary of State Rex Tillerson. “It’s closer than it was with previous administrations, which might be surprising to some people, but that’s a fact of life.”

Traditionally, U.S. presidents have prioritized visits with their Mexican counterparts soon after taking office, considering the close ties between the neighboring countries.

But in January 2017, just days into Trump’s presidency, Peña Nieto called off a planned trip to meet Trump in Washington amid an escalating war of words between the two leaders over Trump’s border wall proposal.

In a Jan. 28, 2017, phone call, a transcript of which was published last year by The Washington Post, Trump suggested to Peña Nieto that they both try to gloss over their respective wall positions by saying “we will work it out” whenever asked whether Mexico would pay for the wall.

“The fact is, we are both in a little bit of a political bind because I have to have Mexico pay for the wall,” Trump told Peña Nieto. “I have to. I have been talking about it for a two-year period. . . . If you are going to say that Mexico is not going to pay for the wall, then I do not want to meet with you guys anymore because I cannot live with that.”

Since that call, Trump has not visited Mexico City and Peña Nieto has not been to Washington, although the two presidents have spoken by phone and met in person in July at the Group of 20 summit in Germany. The two also met in summer 2016, when Trump traveled to Mexico City as a candidate.

Earlier this month, a delegation of Mexican officials led by Videgaray met at the White House with senior adviser Jared Kushner — the president’s son-in-law, who is charged among other things with managing the U.S.-Mexico relationship — national security adviser H.R. McMaster and other Trump administration officials to work out the parameters for a Peña Nieto visit, officials said.

The Mexican officials left the Feb. 14 meeting believing they had an agreement with the U.S. side that Trump would not embarrass Peña Nieto by bringing up his desire for Mexico to fund the wall — a proposition Peña Nieto’s government considers humiliating.

One Mexican official describing his country’s position said, “You cannot talk about the bloody wall.” This official said Videgaray left Washington believing Trump would not broach the wall during Peña Nieto’s visit.

Trump and Peña Nieto made plans to speak by phone Feb. 20, and, assuming the call went well, their staffs would finalize an itinerary for the Mexican president’s White House visit.

But the call did not go smoothly, according to officials from both governments. Trump said he would not be bound by any such agreement and could not commit himself to not talking about the wall.

“That was a dealbreaker for us,” the Mexican official said, adding that Peña Nieto and his administration were concerned in particular about a reporter asking a question about funding for the wall at a news conference and Trump answering it.

Instead of announcing a date for a meeting in Washington, the statements issued by both governments summarizing the call were vague and said only that they had discussed their bilateral agenda on trade, security and migration issues. The statements also said the two presidents exchanged condolences for the high school gun massacre in Parkland, Fla., and the military helicopter accident in Jamiltepec, Oaxaca.

Homeland Security Secretary Kirstjen Nielsen, whose department is responsible for border issues, has canceled an upcoming visit to Mexico. A Department of Homeland Security official denied Saturday that Nielsen’s trip was scratched because of Trump and Peña Nieto’s disagreement, saying the decision to “postpone” her Mexico trip was made a week before the two presidents spoke.

U.S. officials said Trump and Peña Nieto agreed to have their staffs continue talking and try to reach an agreement about the border wall and other issues. A few hours after the two presidents spoke, officials said, Kushner called Peña Nieto to help smooth things over.

U.S. officials said they anticipate that Peña Nieto may try again to visit Washington, perhaps in the spring, and the Mexican official suggested that the two presidents may get together in April at the Summit of the Americas in Lima, Peru.

“Build the wall!” was a signature slogan of Trump’s campaign and has continued to be one through his presidency, even though Congress has not yet fully funded its construction. At his rallies, Trump would cry out, “Who’s going to pay for the wall?” His crowds would shout their answer back: “Mexico!”

Speaking Friday at the Conservative Political Action Conference in Maryland, Trump told his fans, “Don’t worry, you’re getting the wall,” adding that whenever he hears someone suggest that he does not really want to build a wall, “the wall gets 10 feet higher.”

Trump’s statements are considered offensive and outright racist by many Mexicans, who accuse the U.S. president of using their country as a punching bag to motivate his most fervent supporters.

In private, Mexican officials bristle at Trump’s claims that their government is passively allowing drugs and Central American migrants to pass through en route to the United States.

The number of Central Americans detained and turned back by Mexican authorities has at times exceeded the number caught by U.S. border agents, but enforcement by the Peña Nieto government appears to have waned in recent years.

Still, there is an understanding in Mexico that Trump is playing to his national interests, according to Larry Rubin, a businessman who for years has been a leader among U.S. Republicans on Mexico.

“There’s a better understanding of where President Trump is coming from and what his objective is and what his style is,” Rubin said. “Like in any negotiations, there is always posturing or issues that countries don’t agree with. But overall they have so many similarities.”

Carol D. Leonnig contributed to this report.