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.”