Foreign diplomats believe Jared Kushner, left, has the ear of his father-in-law and can curb Trump’s impulsiveness. (Jabin Botsford/The Washington Post)

The scene in the Oval Office was remarkable: the foreign minister of Mexico — the very country that Donald Trump had turned into a campaign-trail ­piñata — huddled with now-President Trump and his son-in-law, Jared Kushner.

The men were debating what Trump would say in a speech later that day as he ordered construction of a wall at the U.S.-Mexico border. The Mexican diplomat, Luis Videgaray, and Kushner, a White House senior adviser, had concluded that the remarks as drafted would upend the two countries’ fragile relationship, so together they urged Trump to soften his language about Mexico.

The trio arrived at a compromise, according to a half-dozen U.S. and Mexican officials who detailed the encounter. Trump, understanding that Mexicans would hang on his every word, agreed to state that a strong Mexico was in the best interests of the United States. In Mexico City that afternoon, Jan. 25, officials welcomed Trump’s remarks as the most encouraging statement he had given to date about Mexico — and they celebrated Kushner as a moderating influence.

Relations ruptured anew only hours later, however, after a war of words between Trump and Mexican President Enrique Peña Nieto — punctuated by an angry Twitter missive from Trump the next morning while Videgaray was back at the White House.

Trump promised a foreign policy based on unpredictability, and by that measure, he is delivering. The messy episode involving a neighbor and longtime ally encapsulates his administration’s emerging foreign policy, one that mingles the president’s public bellicosity with Kushner’s behind-the-scenes diplomacy.

(Deirdra O'Regan/The Washington Post)

Although Kushner, 36, has no traditional foreign policy experience, he has become the primary point of contact for presidents, ministers and ambassadors from more than two dozen countries, helping lay the groundwork for agreements, according to U.S. and foreign officials with knowledge of the contacts. He has had extensive talks with many of these diplomats, including in Europe, the Middle East and the Asia-Pacific region, the officials said.

[9 foreign policy issues the Trump administration will have to face]

Kushner’s back-channel communications with Mexico — the full extent of which has not been previously reported — reveal him to be almost a shadow secretary of state, operating outside the boundaries of the State Department or the National Security Council.

Videgaray had come to the White House on Jan. 25 for a full day of private meetings, but it was Kushner who gave him a heads-up that Trump would deliver a speech that afternoon at the Department of Homeland Security where he would sign an executive order on his signature border wall.

And it was Kushner who led Videgaray into the Oval Office for an unscheduled audience with the president, where together they made their case to Trump for a more measured discussion of Mexico.

The president agreed.

“We also understand that a strong and healthy economy in Mexico is very good for the United States — very, very good,” Trump said in his speech. “I truly believe we can enhance the relation between our two nations to a degree not seen before, certainly in a very, very long time.”

Kushner, center-right, reaches out to greet Sen. Orrin G. Hatch (R-Utah) during a meeting in the Roosevelt Room of the White House on Feb. 2. To Kushner’s right is Peter Navarro, director of the National Trade Council, and Rick Dearborn, a deputy White House chief of staff. (Jabin Botsford/The Washington Post)

But Videgaray and Kushner’s victory was short-lived.

So strong were the anti-Trump political winds at home that Peña Nieto felt compelled to go on television that night to declare that Mexico would never pay for the border wall.

This angered Trump, who tweeted at 8:55 Eastern time the next morning that he and Peña Nieto should cancel their upcoming summit if Mexico refused to pay for the wall. Peña Nieto called off the visit and in a brief phone call instructed Videgaray — back at the White House for another round of meetings — to leave and come home.

The mission was aborted, according to the officials’ accounts, and Kushner seethed with frustration at the outcome. Kushner declined to be interviewed.

Some of the leaders who have dealt with Kushner said they were initially skeptical but found him to be a good listener and courteous intermediary who quickly intuits the core of their issues and can facilitate meetings throughout the administration.

One of his top ambitions is to help broker peace in the Middle East — something with which the president has publicly tasked him — and Kushner, an Orthodox Jew, quietly has taken an active role in helping select ambassadors to that region.

“Everyone is trying to get to know Jared Kushner,” said the ambassador from one U.S. ally, who spoke on the condition of anonymity to be candid. Many ambassadors were loath to put even their positive thoughts about Kushner on the record for fear of jeopardizing what has become their most important contact in Trump’s Washington.

Kushner’s role as a ­foreign-policy fixer is, on the surface, an unlikely one. He came of age as the oldest son in a Democratic real estate family and as a young man initially divided his attentions between his family’s business and the New York Observer, a newspaper he purchased in 2006.

In Trump’s inner circle, Kushner draws plaudits for smoothing feathers ruffled by his father-in-law’s more erratic moves — with some aides bemoaning that on Saturdays, when Kushner observes Shabbat and does not work or use electronic devices, the workings of the White House sometimes devolve.

Still, the president risks ­undermining Kushner’s best efforts with his erratic compulsions, short attention span and tendency to lash out at real or perceived slights, as happened in the case of Mexico.

The White House, however, argues that the relationship between the United States and its southern neighbor is improving. “Our relationship with Mexico continues to grow stronger,” White House press secretary Sean Spicer said. “They’re excited to pursue both economic and security areas of interest, and we continue to have a very, very healthy bilateral relationship.”

In the Mexico talks, the relationship between Kushner and Videgaray, who met through friends in the financial world, has proved pivotal, especially for Mexico. They had forged a personal bond and had managed to help bring together Trump and Peña Nieto, whose public positions and rhetoric are at extreme odds.

Kushner has inquired about books and articles on the history of U.S.-Mexico relations, and Mexican officials said Kushner offers Trump a different perspective from the one the president has formed based on his opposition to illegal immigration and trade deals he considers unfair to U.S. workers.

“Videgaray has in his favor a close relationship with Jared, and that opens a direct channel of communication with Trump,” said Rafael Fernández de Castro, a professor at the ITAM university in Mexico City. But he added that “the son-in-law is not going to save us.”

[For Trump son-in-law and confidant Jared Kushner, a long history of fierce loyalty]

There appear to be limits to Kushner’s influence. The leaders of both countries are at a stalemate, not only over the border wall but also over trade, with Mexico trying to preserve the North American Free Trade Agreement that Trump campaigned against.

Further complicating the relationship are domestic political pressures.

“The president of the United States is speaking to his issues and his base, and our president is speaking to most of Mexican society, which has roundly rejected the way the new U.S. administration has talked about Mexico,” said Arturo Sarukhán, a former Mexican ambassador to the United States.

Bill Richardson, a Democrat who is a former governor of New Mexico and U.S. ambassador to the United Nations, said the U.S.-Mexico relationship is at its lowest point in generations.

“The threats on paying for the wall, the threats to renegotiate NAFTA, the threats of the import fee have stoked a real nationalism in the Mexican people that is going to give President Peña Nieto very little room to maneuver,” said Richardson.

Navigating these challenges on Peña Nieto’s behalf is Videgaray, one of his closest advisers. Videgaray was Mexico’s finance minister last year when Peña Nieto tasked him with outreach to the Trump campaign, where he cultivated a friendship with Kushner.

Videgaray and Kushner arranged Trump’s trip to meet Peña Nieto in Mexico City in August — a visit so controversial that Videgaray was forced to resign. But even without an official post, Videgaray remained close to Kushner, flying to New York to meet. And after Trump won, Videgaray was back in the good graces of Peña Nieto, who named him foreign minister.

“He has access to people close to Trump,” said Raúl Benítez Manaut, a political analyst and professor at Mexico’s National Autonomous University. “Videgaray’s job is to do damage control.”

Videgaray visited Washington just five days after Trump’s inauguration and had roughly eight hours of meetings at the White House on Jan. 25 with Kushner and Trump as well as White House chief of staff Reince Priebus, chief strategist Stephen K. Bannon, National Economic Council Director Gary Cohn and National Trade Council head Peter Navarro. He has become so well known in the West Wing that aides refer to him by his first name.

The tweet that ended the comity was perhaps as predictable as it was strident, and the fallout was swift. Kushner was angry about the situation and Videgaray cut short his trip, canceling a scheduled meeting with John F. Kelly, the secretary of homeland security, the officials said.

But Kushner and Videgaray kept talking. The two helped arrange a follow-up call between Trump and Peña Nieto, which officials in both countries described as tough at times but largely cordial and constructive, including a discussion on combating drug cartels.

“I think he’s a very good man,” Trump said of Peña Nieto in a recent interview with Fox News. “We have a very good relationship.”

Kushner helped facilitate yet another trip for Videgaray to Washington, where on Wednesday he met privately with Kelly and Secretary of State Rex Tillerson.

In another sign of Kushner’s growing importance, Tillerson invited him to his meeting with Videgaray, which for the first half-hour was just the three men — the U.S. secretary of state, the Mexican foreign minister and the U.S. president’s son-in-law — before they were joined by aides.

The diplomatic community is taking note, viewing Mexico as a guinea pig. Senior officials from several other countries have already reached out to their Mexican counterparts, hoping to glean insights about the new president, the changing geopolitical dynamics in Washington and the quiet, dimpled man behind it all — Kushner.

Partlow reported from Mexico City.