WASHINGTON— Donald Trump has provoked U.S. allies for years, questioning NATO’s relevance, demanding greater financial contributions and recently musing about the possibility of not protecting members who aren’t paying enough for defense.

Now, with members of the alliance and other U.S. partners converging on Washington this week to celebrate the 75th anniversary of the North Atlantic Treaty Organization, heads of state are scrambling to find a common language with the Republican presidential candidate whose chances of winning in November have grown, according to the latest poll numbers .

Their most urgent concerns are over Ukraine : Trump has declared he would single-handedly end the war by forcing Kyiv and Moscow into a peace deal before he is even sworn into office. With Moscow demanding that Ukraine forgo eventual NATO membership and cede swaths of its territory, some alliance members fear that Trump could try to bully Kyiv into a capitulation or might not continue sending the weapons necessary for Ukraine’s military to keep fighting.

Polish President Andrzej Duda , who traveled to Trump Tower in New York City in April for a two-and-a-half-hour meeting with the former president, told The Wall Street Journal that he spoke about the strategic importance of Ukraine. Duda declined to go into details about the dinner, other than to say they dined on “tasty steak.”

“I presented my point of view to him, my assessment of the situation,” he said, adding that he had successfully worked with Trump during his time in the White House.

Such outreach by foreign officials has become common, said Keith Kellogg , a retired three-star Army general who served as the national-security adviser to then-Vice President Mike Pence and earlier held senior positions in Trump’s National Security Council. Kellogg doesn’t speak for Trump or the president’s campaign, but as a former and potentially future member of Trump’s inner circle, he has been a much sought-after interlocutor.

“Since last November we have had over 160 contacts with foreign officials,” said Kellogg, who is part of the America First Policy Institute, which promotes Trump’s foreign policy. Those reaching out include ambassadors, foreign ministers and defense ministers, he added.

“We talk to all of them,” he said. “Simply put, politically they are hedging their bets.”

Trump’s penchant for unpredictability has made the job of outreach by governments more challenging, particularly because the campaign hasn’t officially designated specific people to represent Trump on foreign policy. With limited insight into who will influence him in a new cabinet, some countries are leveraging whatever contacts they have, or are reaching out to Trump himself.

German Chancellor Olaf Scholz invited key pro-Trump legislators to dine with him during his visit to Washington in January and the following month at the Munich Security Conference, a global geopolitics forum. His most senior aide, Wolfgang Schmidt , minister of the chancellery, has been traveling to Washington several times a year since Russia invaded Ukraine.

Apart from his official dealings with the Biden administration, Schmidt has been building a network among Trump backers that includes donors, legislators and former Trump administration officials.

But personal rapport between leaders might not be enough to overcome flare-ups with Trump over NATO, whose members are moving this week to reaffirm its long-term goal to bring Ukraine into the alliance. A senior Biden administration official said Friday that the NATO summit communiqué “will include very strong signals of Allied support for Ukraine on its path to Euro-Atlantic integration.”

Trump, by contrast, blamed Western promises to bring Ukraine into the alliance for provoking Russia to invade the country in the first place. “I think that’s really why this war started,” he said during a June interview with the “All-In” podcast.

During his debate with President Biden, Trump said that if he were elected in November he would have the war settled before he even took office on Jan. 20. Trump didn’t provide details on how he plans to bring an end to the conflict, though he said he wouldn’t accept Russian President Vladimir Putin ’s territorial demands.

But Kellogg spelled out one possible way, which would mark a radical break with the alliance’s current strategy Under Biden, the U.S. and NATO have provided military support to Ukraine on an open-ended basis, hoping Ukrainian gains on the battlefield would enable Kyiv to pursue what it considers to be an acceptable solution.

In contrast, Kellogg and Fred Fleitz , the former chief of staff of Trump’s National Security Council, wrote in a paper published by the America First Policy Institute that the U.S. should press for a cease-fire, take NATO membership for Ukraine off the table for an extended period and then push Kyiv and Russia to negotiate a peace to stop the fighting.

“You turn to Ukraine and say, ‘If you don’t support this kind of deal, then our support dries up,’ ” Kellogg said. “You turn to the Russians and say, ‘If you don’t support a negotiated deal, then we will give Ukraine everything militarily that the United States has not provided in massive numbers.’ ”

Putin said last week that he welcomed Trump’s talk about seeking a settlement to end the fighting in Ukraine, though he said he didn’t know any details of his plan.

Trump supporters say the former president’s broader goal is to strengthen alliances by encouraging laggards to boost their contributions. But John Bolton , who served as Trump’s national-security adviser from 2018 to 2019, said Trump thought about withdrawing from NATO as president and might do so if re-elected.

“I think it laughable to say he is trying to reform NATO,” Bolton said. “He doesn’t understand what collective defense alliances are. He believes essentially that we are providing defense services for these allies, and they’re not paying enough.”

Foreign officials outside of NATO are also building ties with Trump and his inner circle in the hope of influencing or at least blunting his future decisions on fractious issues over trade and national security.

Japan, whose prime minister is expected to attend the NATO summit along with other partners, wants to ensure Trump doesn’t put tariffs on its goods and maintains the U.S.-Japanese alliance. It has centered its outreach around former Prime Minister Taro Aso , 83 years old, who was Japan’s finance minister during the Trump administration. Aso, who currently holds the No. 2 post in the ruling Liberal Democratic Party, spent time with the former president in Trump Tower in April.

Japan’s former national-security adviser, Shigeru Kitamura , has a business relationship with his counterpoint in the Trump administration, Robert C. O’Brien . The men each run their own consulting firms, which have a strategic partnership. “I think we’ve established pretty good personal relationships,” Kitamura said.

Australia, whose deputy prime minister plans to attend the summit, has already taken steps that appear to prepare for Trump’s possible return. Former Prime Minister Scott Morrison met with Trump in May, sparking speculation that he could be Australia’s next U.S. ambassador if his center-right Liberal Party returns to power in coming elections.

Even Mexico is trying to forge personal ties. A Trump victory could pose a challenge to Mexico’s first female and Jewish president , Claudia Sheinbaum , a leftist academic who is to take office in October.

While Trump was able to establish a solid working relationship with departing nationalist President Andrés Manuel López Obrador , Trump and Sheinbaum are unlikely to develop such personal affinity, current and former Mexican officials say.

A telling sign that the incoming Sheinbaum administration is getting ready for a potential Trump victory is that she has named former Foreign Minister Marcelo Ebrard as the country’s future economy minister. Ebrard, who led talks with the Trump administration when the U.S. threatened to impose 25% tariffs, will serve as a top negotiator for the review of the U.S.-Mexico-Canada Agreement scheduled for 2026.

Still, personal ties can only go so far, and European leaders are worried about the NATO alliance as well as their relations with Washington, said Tony Housh , head of the American Chamber of Commerce in Poland.

Warsaw’s military spending is well above the NATO average at more than 4% of GDP. Poland also has signed $50 billion of U.S. arms contracts over the past two years and has agreed with Westinghouse on a $20 billion nuclear-power plant, the country’s first.

“If Poland has good ties with Washington, that’s important, but it still needs to bring the rest of Europe along with it to ensure its security,” Housh said. “The U.S., by itself, isn’t enough.”

Write to Michael R. Gordon at michael.gordon@wsj.com and Alan Cullison at alan.cullison@wsj.com