Side by side, a lone Mexican flag behind them, the men stood, one of the most unlikely political pairs imaginable.

Donald Trump, the Republican nominee who has built his campaign around blaming Mexicans for the loss of American jobs and safety; and President Enrique Peña Nieto, the unpopular Mexican leader who stunned his country, and even members of his government, by extending an invitation to Trump for a visit.

In the end, neither man chose to fuel the cross-border shouting match that Trump’s campaign launched a year ago — a result that probably favored Trump. Many Mexicans had hoped their president would demand an apology or forcefully reject Trump’s plans to build a border wall (and make Mexico pay for it), deport millions and weaken trade ties between the neighbors.

Instead, Peña Nieto played the role of professor-in-chief, listing economic statistics about the mutually beneficial U.S.-Mexico relationship, while a reserved, almost somber Trump announced that he had made a new “friend.” The Republican candidate still, however, got in some jabs about how they did not have a chance to discuss “who pays for the wall.”

Republican presidential nominee Donald Trump is slated to meet with Mexican President Enrique Peña Nieto as he tries to clarify his past comments about Mexico and immigration. (Jenny Starrs/The Washington Post)

Mexicans were outraged to learn that Trump had been invited to visit Mexico, and the news conference Wednesday struck many here as disappointing. After months of bearing the brunt of Trump’s attacks, Mexicans found Peña Nieto’s performance a letdown.

“He’s not going to convince anyone with his talk about building dialogue and bridges,” said Jose Antonio Crespo, a Mexico City political science professor. “If Trump wins, they’ll have to meet and work together, but for now, the annoyance and anger of the people about his speech prevails.”

“Trump benefited from this encounter,” he added. “The president failed, he lacked strength.”

Mexicans learned only the day before that Trump would be visiting. Even at the highest levels of government, Mexicans were baffled at what Peña Nieto had to gain by welcoming a man so widely reviled in this country.

In the best of times, Mexicans feel conflicted about their neighbors to the north. In Trump, many Mexicans see the embodiment of their worst fears: an overbearing and insulting American politician happy to tread all over his country’s poorer neighbor. The Mexican leader, struggling through the second half of a difficult six-year term, has himself compared Trump’s rhetoric to that of Adolf Hitler.

“It’s kind of a big question mark,” said one senior Mexican official, speaking on the condition of anonymity to be candid. “This is not a winning proposition having him here.”

After an hour behind closed doors at Los Pinos, the presidential palace, Trump and Peña Nieto emerged and took their places at adjacent podiums. Peña Nieto apparently sought to take the high road, discussing the importance of the relationship, while pledging to respect the electoral process of the United States.

He rattled off trade and job statistics: $500 billion in annual trade between the neighbors, some 6 million jobs in America that depend on Mexican exports. He said his job was to defend Mexicans — those at home and the millions in the United States — who are “honest and hardworking people.”

“They are good people. They respect family. They respect community life, and they respect the law,” Peña Nieto said. “Mexicans deserve the respect of everyone.”

Trump responded that it was a “great, great honor to be invited to Mexico.”

He said he had “tremendous feelings” for Mexican Americans, not only friends, but his employees. While he listed familiar goals for the region — like ending illegal immigration and raising pay for workers — he did not blame Mexico as directly as he had in the past for problems in the United States.

When reporters shouted out questions about Trump’s proposed border wall, the Republican candidate said he had mentioned it to the Mexican leader. “We didn’t discuss payment of the wall. That will be for a later date.” But Peña Nieto’s spokesman said that during the talks, the Mexican leader rejected the wall.

The firmest Peña Nieto got in his public comments was when he mentioned that some of Trump’s comments hurt Mexicans — but then he quickly defended Trump.

“I was sure that his genuine interest is to build a relationship that lets us bring to our societies better conditions,” he said.

Eduardo Sanchez, the president’s spokesman, said that Peña Nieto had long intended to invite both American presidential nominees here, to get to know them and share “the importance that Mexico has for the U.S.”

The easy move, he said, would be for Mexico to refuse to speak to Trump.

“The calculus of Peña Nieto is not his popularity, it’s his responsibility,” Sanchez said.

But the decision to invite Trump was assailed by a wide range of Mexicans.

Sergio Sarmiento, a political commentator and radio host, said none of the callers to his show have supported the visit.

“There have been hundreds of calls from people, [all] negative,” he said. “This will not help Peña Nieto at all.”

Former president Vicente Fox, an outspoken Trump critic, told Milenio TV that Trump was not welcome and that “he has offended us, he has deceived us, he has discriminated against us.”

Peña Nieto, once seen as a reformer who opened up Mexico’s oil sector to foreign investment, took on long-standing monopolies and proposed ambitious changes to the education system, has lost much of the momentum he had on taking office in late 2012. A recent poll in Mexico’s Reforma newspaper put his approval rating at 23 percent, the lowest in the two decades that the newspaper has been tracking presidential popularity.

The oil reform has yet to take off amid low global prices for petroleum. Mexico’s homicide rate declined early in his term but has risen again, jumping 16 percent in the first five months of this year over the same period last year.

And the president has been beset by scandals. One involved a favored government contractor who bought houses on behalf of Peña Nieto’s wife, who is a former TV star, and finance minister. Forty-three students from the state of Guerrero disappeared in 2014, and huge protests erupted when information emerged suggesting that they were captured and killed with the help of police.

Recently, Mexico’s human rights commission reported that 22 of 42 suspected drug cartel members killed at a ranch in Michoacan last year were allegedly executed by police and not killed in a gunfight as police had claimed. That contributed to the ousting of the head of the federal police this week.

Peña Nieto’s Institutional Revolutionary Party struggled in the midterm elections in June, losing governorships it had long held.