LONDON — It had all been going so well.
Prime Minister Theresa May of Britain had just left Washington on Friday evening after a tense but successful first visit with President Trump for a 10-hour flight to Ankara, Turkey, for her next awkward encounter, with the increasingly autocratic Turkish president, Recep Tayyip Erdogan.
By the time she had landed in Turkey, however, Mr. Trump had signed his executive order halting entrance to the United States of all Syrian refugees and of most citizens from seven predominantly Muslim countries. Mrs. May was beginning to feel the backlash.
After she termed the executive order an American issue, criticism erupted even among her own members of Parliament. She was accused of appeasement by a former British diplomat. Protesters gathered outside Downing Street on Monday night, and more than 1.5 million signatures collected on an internet petition demanding that Mrs. May rescind her invitation for Mr. Trump to visit Queen Elizabeth II.
A close relationship with any American president is regarded as crucial by allies and foes alike, but especially by intimates like Britain, Canada, Japan and Mexico. Yet like moths to the flame, the leaders of those nations are finding that they draw close at their peril.
One Western leader to escape this fate so far is the German chancellor, Angela Merkel, who has kept a cool distance from Mr. Trump. In a telephone call on Saturday, she reminded him of Washington’s obligations under the Geneva Conventions to accept refugees fleeing war, a view underlined by her official spokesman.
The danger of playing nice with Mr. Trump should come as little surprise to his country’s allies. Besides campaigning on an “America First” platform, he has regularly argued that allies have been taking the United States for a ride, in trade, security and financial terms.
While he has been cordial in public settings with the leaders of those allied nations, Mr. Trump has turned on them soon afterward.
“The problem for May is that Trump doesn’t value relationships. He values strength and winning,” said Jeremy Shapiro, the director of research at the European Council on Foreign Relations and a former senior State Department official. “If you rush to the White House to offer a weak hand of friendship, you guarantee exploitation.”
While Mr. Trump’s executive order was clearly not aimed at Britain, he signed it on Friday, just a few hours after Mrs. May left. “You can show up at his doorstep and hold his hand so he doesn’t fall down a ramp, but that doesn’t mean a few hours later when he’s signing an order he thinks at all about how it affects you, your politics or your citizens,” Mr. Shapiro said.
Particularly problematic for Mrs. May was her offering the invitation to Mr. Trump to undertake a state visit with Queen Elizabeth II this year, which was accepted. The internet petition to Parliament calling for the cancellation of the invitation says the visit “would cause embarrassment to Her Majesty the Queen.”
Amber Curtis, 21, a film student who is half-British and half-Iranian, said that she worried for her family and friends in America. “It sends a bad message if he comes here after this ban,” Ms. Curtis said of Mr. Trump. “I wouldn’t say that I want no relationship at all, but he cannot come here under the terms of this ban. The terms need to be renegotiated.”Negma Yamin, 50, a teacher of Pakistani origin, was in tears. “I’m so upset as a fellow Muslim; I hate the persecution,” she said. Mrs. May “should absolutely have no relationship with him,” she added. “You can’t negotiate with a person like that. What is he going to do with the people? He’s dividing the U.S., he’s dividing the world.”
On Monday, Downing Street insisted that the invitation stood. But who knows how Mr. Trump will react?
The Mexican president, Enrique Peña Nieto, has had a similar experience to Mrs. May’s — twice. Last year, in the name of conciliation and dialogue, he invited Mr. Trump to Mexico, a somewhat questionable move given Mr. Trump’s contempt for Mexico and his promises to renegotiate the North American Free Trade Agreement, raise tariffs, deport millions of Mexicans, and build (or finish) a border wall and make the southern neighbor of the United States pay for it.
The visit was widely viewed in Mexico as a national humiliation. It left Mr. Trump looking stronger and Mr. Peña Nieto looking weaker, especially when Mr. Trump, in an immigration policy speech in Phoenix the same day, insisted again that Mexico would pay for the wall.
Mr. Peña Nieto persisted after Mr. Trump’s election, apparently aiming, like Mrs. May, to influence the new president and to moderate what many hoped was just hyperbolic campaign talk. But just before the two men were to meet in Washington, Mr. Trump issued executive orders calling for the wall and greatly restricting immigration.
An editorial in the Mainichi Shimbun, a center-right paper in Japan, questioned why Mr. Abe was not taking a stronger stand against Mr. Trump: “It is hard to understand why the prime minister is defending a president who destroyed the trade accord — formed after nearly six years of arduous negotiations — on his fourth day in office.”
Given the stakes, Mr. Abe has refrained from open criticism of Mr. Trump and is scheduled to meet with him in Washington early in February.
The Trump effect has been felt even in Australia, where Prime Minister Malcolm Turnbull has come under criticism for saying it is not his job to comment on the domestic policies of other countries. This after securing a pledge from the president on Sunday to honor an Obama administration agreement to accept refugees detained on the Pacific islands of Nauru and Manus.
In Canada, too, the prime minister, Justin Trudeau, has had his Trump moments. Mr. Trump is deeply unpopular in the country, but as Mr. Trudeau’s father, former Prime Minister Pierre Trudeau, once said, proximity to America “is in some ways like sleeping with an elephant; no matter how friendly or temperate the beast, one is affected by every twitch and grunt.”
So instead of provoking a fight, Mr. Trudeau moved swiftly to make contact with officials in the new administration and reshaped his cabinet to promote ministers with experience in the United States.
Mr. Trump made problems right away for the Canadian leader by giving the go-ahead to the Keystone XL pipeline, putting Mr. Trudeau in an uncomfortable position between environmentalists and oil producers.
If Mr. Trump goes after Canada on trade issues, as seems likely, Mr. Trudeau is expected to become significantly more vocal and critical.
After fumbling its initial response, Britain got essentially the same clarification 15 hours later, which London hailed as a result of its special relationship with Mr. Trump. While Britain may have been influential, however, the White House was already narrowing the initial interpretations of the executive order.
But not before Mrs. May was attacked for timidity in the face of outrage by her own legislators and by the opposition.
Still, the “special relationship” has never been an equal one, so some degree of humiliation often goes with the territory.
As one message on Twitter, posted by the user @Locke1689, a professed “progressive conservative,” read: “Actively snubbing the world’s only superpower would be gross diplomatic self-harm.”
A version of this article appears in print on January 31, 2017, on Page A1 of the New York edition with the headline: Allied Leaders Extend a Hand at Their Peril.