SHANNON, Ireland — President Trump reassured Ireland’s prime minister, Leo Varadkar, on Wednesday that Britain’s exit from the European Union would “work out very well,” including for Ireland, “with your wall, your border.”
This remark prompted the Irish leader to reply “one thing we want to avoid, of course, is a wall or border between us.”
Mr. Trump’s comments, made before a meeting with Mr. Varadkar at Shannon Airport, were the latest example on this European trip of the president’s glancing knowledge of political issues that are often deeply divisive in the countries he visits — as well as his willingness to reverse course when he raises hackles.
How the border between Northern Ireland and the Irish Republic will be handled, if Britain leaves Europe, is one of the most vexing issues of the Brexit debate and one that deeply concerns people in both the north and the south who worry it could reawaken the ancient enmities of the era known as “the Troubles.”
Mr. Trump, of course, advocates a border wall with Mexico as the solution to America’s immigration crisis, and he seemed to draw a parallel to Ireland. “I mean, we have a border situation in the United States, and you have one over here,” he said. “But I hear it’s going to work out very well here.”
When Mr. Varadkar, an impassioned opponent of Brexit, jumped in to note that rather than putting up a new wall, the Irish were trying to prevent an old barrier from going back up — in the form of a hard border between Northern Ireland and the southern Republic — Mr. Trump readily agreed.
“The way it works now is good, you want to try and keep it that way,” the president said, pivoting quickly to embrace his host’s antipathy for walls. “I know that’s a big point of contention with Brexit.”
It was reminiscent of Mr. Trump’s 180-degree turn a day earlier on whether trade talks with the United States would require Britain to open up its public health system to American competitors. Asked about it during a news conference with Prime Minister Theresa May, Mr. Trump said everything would be on the table.
Sensing the negative reaction his comments provoked, Mr. Trump reversed course in an interview with the broadcaster Piers Morgan, which aired on Wednesday. No, Mr. Trump said, he did not believe the health system needed to be part of a trade deal. “I don’t see it being on the table,” he said.
There is usually little cause for tension between an American president and an Irish taoiseach (pronounced THEE-shakh), which is how prime ministers here are known.
Mr. Trump, who owns a golf club in nearby Doonbeg, Ireland, spoke warmly of his many Irish friends at home.
Mr. Varadkar made clear how closely Ireland works with the United States — noting, for example, that the administration had offered it security briefings on what the Americans have called the threat posed by the Chinese telecommunications company, Huawei.
Still, the two leaders were an awkward match: Mr. Varadkar, a 40-year-old gay man of mixed Indian and Irish heritage, known for his cool manner; and Mr. Trump, a 72-year-old former New York real estate developer who runs hot and is known for his political incorrectness.
Mr. Varadkar also has a complicated history with Vice President Mike Pence. This March, he brought his partner, Matt Barrett, to an annual St. Patrick’s Day breakfast hosted by the vice president, implicitly rebuking Mr. Pence for his history of hostile statements about homosexuality.
“I stand here this morning as leader of my country, flawed and human, but judged on my political actions and mistakes and not on my sexual orientation or my skin tone or my gender or my religious beliefs,” the prime minister said.
The logistics for Wednesday’s meeting were complicated. The White House wanted Mr. Trump to play host to Mr. Varadkar at his golf club, but that posed a protocol problem for the Irish government, which countered with Dromoland Castle.
After reports the visit was going to be scrubbed, the two sides compromised by agreeing to meet at Shannon Airport — which is why, when Mr. Trump landed in this land of castles and quaint villages, he sat down with Mr. Varadkar in a V.I.P. lounge, across the hall from a bar and a duty-free shop.
Once a gateway to Europe, Shannon is now a popular refueling stop for senior American officials. Hillary Clinton used to browse in the shop when she was secretary of state; John F. Kerry drank Irish coffee there with reporters.
For Mr. Trump, it was a respite from the somber rituals of D-Day memorials, even though his visit here included the complicated politics of modern-day Europe. As a major local employer, Mr. Trump is popular in this part of the country, unlike in Britain or other parts of Ireland. Residents of West Clare, where the club is, warned protesters to stay away.
Mr. Varadkar has labored to have cordial relations with Mr. Trump, even as he quietly cultivated his predecessor, Barack Obama. On his visit to Washington this year, Mr. Varadkar requested a private meeting with Mr. Obama, according to The Irish Times. Some here worried that would antagonize the current president.
Mr. Trump showed little sign of it, even when an Irish reporter reminded him that Mr. Varadkar once described his policies on climate change as “pernicious and reckless.”
“Well, I haven’t heard those comments,” Mr. Trump said. “The prime minister has done a fantastic job, and we’ve become friends over the last very short period of time.”