WARSAW, Poland — The president of the Polish bishops’ conference cautioned Polish and Hungarian political leaders against fostering nationalism and xenophobia as both countries face European Union sanctions over their alleged authoritarian direction.

Archbishop Stanislaw Gadecki of Poznan acknowledged that patriotism “characterizes our nations and is a great value,” but urged vigilance so that patriotic values do not “give rise to … contempt for others.”

“Given our common history, we should strive to be linked not just by a shared past, but also by a shared future,” Gadecki said in his homily March 23 at a Mass for Polish-Hungarian Friendship Day in St. Michael Cathedral in Veszprem, Hungary.

President Andrzej Duda of Poland and President Janos Ader of Hungary attended the Mass, along with church leaders from the two traditionally Catholic countries.

Gadecki said Poles and Hungarians were closely linked by shared historical experiences, from their 10th-century Christian conversion to their re-emergence as parliamentary democracies after the 1989 collapse of communist rule.

He added that both had joined the European Union in May 2004 and should stand together defending Christian values and facing national challenges.

“Yet true friendship isn’t exclusive or closed in its own circle. It should also be open to others, thus presenting new perspectives for the future,” he said.

“We often want to be viewed as the best and wisest, and often develop a false image of our friends. But the self-knowledge process should mean not just highlighting our merits but also admitting our faults and failures.”

The center-right governments of Poland and Hungary, respectively headed by prime ministers Mateusz Morawiecki and Viktor Orban, have been widely criticized for policies that include a refusal to accept EU quotas for receiving Muslim refugees and asylum-seekers from Syria, Iraq and other war-torn countries.

The EU’s governing commission has threatened to withhold structural funds and take both countries to the European Court of Justice, while also warning it may suspend Poland’s EU voting powers over contested reforms by its ruling Law and Justice party to the judiciary and state media.

In his homily, Gadecki said Poles and Hungarians had supported each other in their past struggles for freedom and should do the same in helping negotiate current issues and problems.

“One argument for seeking political friendship has been power — nations favor alliances with the strongest. But Hungarians and Poles are not such nations today,” the archbishop said.

“Instead, friendship should mean sincerity, trust, sharing sadness and joy, bringing cheer and comfort and helping by example. It should also mean noble-mindedness, unselfishness, sympathy and solidarity.”