BEREHOVE, Ukraine — When the Hungarian State Opera visited a town just over the border in western Ukraine last month to perform a patriotic opera, 3,000 people in the audience rose to their feet for the playing of the Ukrainian and then Hungarian national anthems.
What followed, however, was a striking display of discordant allegiances.
The audience, gathered in the Ukrainian town of Berehove in an outdoor amphitheater, stood mute during the Ukrainian hymn and then burst into boisterous song for the anthem of Hungary, a foreign country.
The spectacle explains why, whether along Ukraine’s border with Russia in the east or on its western frontier with the European Union, border-straddling bonds of language and culture make it so difficult for Ukraine to hang together as a single, unified state. It is a clue as well of the skillful exploitation of nationalist impulses by Hungary’s leader, Viktor Orban, to cement his increasingly autocratic rule.
Mr. Orban has avoided threats of using force to right what he decries as historic wrongs that put millions of Hungarians outside their country’s border. But the fear is that, having positioned himself as the leader of a populist surge across much of Europe with his strident attacks on immigration and the European Union, Mr. Orban now risks reopening Europe’s most dangerous Pandora’s box: the grievances of ethnic groups caught outside their homelands.
The town of Berehove, like the audience at the opera, is made up largely of ethnic Hungarians who mostly speak Hungarian, not Ukrainian, which many do not speak at all, and set their watches according to the time in Hungary, not Ukraine, which is an hour ahead.
“In their heads these people are living in Hungary,” said Vasyl Vovkunovich, a former teacher and furniture seller who in November led a group of fellow Ukrainian nationalists in tearing down a Hungarian flag flying outside the town’s city hall. The group left intact three other flags also on display, those of Ukraine, the European Union and the municipality.
Few nations in the world have had their borders chopped up and lands redistributed as frequently as those in Central and Eastern Europe, and particularly former components of the Austro-Hungarian Empire, which disintegrated after World War I. Berehove, for one, has found itself in five different countries over the past century.
Under the Trianon Treaty in 1920, Hungary — which was allied with the losing side in both world wars — suffered what it still considers the great historical injustice of losing two-thirds of its land.
Fury at the dismemberment of the country has been a constant theme in Hungarian politics ever since, but it has taken on new force in recent years under Mr. Orban’s leadership.
His immediate political calculus is simple: his government has given 1 million Hungarians living outside Hungary passports and the right to vote, creating a large bloc of voters who mostly cheer the robust nationalism championed by Mr. Orban and his party, Fidesz. Hungary itself has only 9.7 million people.
Berehove’s ethnic Hungarian mayor, Zoltan Babek, who said he had not received a passport from Budapest but whose wife has, said nobody is agitating for his town to rejoin Hungary. He insisted he joined in the singing of the Hungarian anthem simply out of courtesy for the visiting opera troupe and the Hungarian consul general, who was in the audience.
But asked whether he considered himself a Ukrainian patriot, he hesitated and then said: “I am a patriot of this town.”
Worried that Hungary is gnawing away at the stability of Ukraine’s western border zone, prosecutors in Transcarpathia, the region bordering Hungary, recently announced the start of a criminal investigation for high treason over the issuing of Hungarian passports to Ukrainian citizens. On Thursday, the Foreign Ministry in Kiev, the Ukrainian capital, ordered the expulsion of Hungary’s consul in Berehove.
The expulsion followed the posting online of a video that showed a group of Berehove residents singing the Hungarian anthem and pledging loyalty to Hungary at a passport-issuing ceremony at the Ukrainian town’s Hungarian consulate. A Hungarian diplomat can be heard warning them not to tell the Ukrainian authorities about their new citizenship. Ukrainian law bars dual nationality.
Mr. Orban’s government insists that it recognizes Hungary’s current borders and has no intention of trying to seize lost lands and rebuild “Greater Hungary,” which includes territory now in Romania, Serbia, Slovakia and Ukraine.
But it has lavished money as well as passports on Hungarians living outside Hungary. His government, while fiercely opposed to multiculturalism at home, has complained loudly about any attempt by countries like Ukraine to force their Hungarian minorities to learn the language and follow the customs of their host nation.
The largest Hungarian diaspora population, more than half of a total of around 2.4 million people, lives in Romania. But the relatively small population of about 150,000 Hungarian-speakers in western Ukraine has become a much bigger source of friction, not least because Mr. Orban keeps picking fights with his weak eastern neighbor.
His government caused outrage in Kiev, the Ukrainian capital, in July when it announced the appointment of a ministerial commissioner for the development of Transcarpathia. At first glance, the announcement suggested just another reshuffling of Hungary’s bureaucratic chairs but for one detail: Transcarpathia is not in Hungary but in Ukraine, so not a place for which Budapest should be appointing officials.
“This is a small, but important detail,’’ said Dmytro Tuzhanskyi, a political scientist and expert on Hungary’s relations with Ukraine in Uzhgorod, the capital of Ukraine’s Transcarpathia region. “It was a mistake, a Freudian mistake. It showed what they are really thinking.”
Hungary, Mr. Tuzhanskyi added, is not about to send “little green men” into Transcarpathia to foment secession, as Russia did in Crimea and eastern Ukraine. But Hungary’s assertive and often prickly nationalism under Mr. Orban has left Ukraine feeling besieged not only in the east by Russia but in the west by Hungary, a member of what is supposed to be its biggest backer, the European Union.
After a heated diplomatic flap, Mr. Orban’s government agreed to change the title of its new ministerial commissioner to avoid any suggestion that it was claiming Ukrainian territory.
The gulf has been widened by hard-line nationalists on both sides, including the Hungarian far-right group Jobbick, which has called for the annexation of Transcarpathia, and it has created a fog of uncertainty in which hotheads — and also Russia — can easily spread unease.
In February, the office in Uzhgorod of the region’s main Hungarian political party, known as KMKS, was hit twice by arson attacks. The second firebombing, far more serious than the first, incinerated the building’s interior and was quickly denounced by Budapest and also Moscow as a provocation by Ukrainian extremists. The Ukrainian authorities, however, insist the attack was the work of a Polish far-right group working for Russia. Poland has arrested two people accused of involvement in the attacks.
At around the same time, Ukraine announced that it would reopen a long-abandoned army base in Beregovo. Budapest swiftly denounced the move as “disgusting,” because, Hungary said, it suggested Ukraine viewed Hungarian residents in the town as a threat.
Some believe that in addition to his domestic political calculations, Mr. Orban wants to prove himself a reliable partner to the Kremlin by unsettling Ukraine. This is the view of liberals in Budapest, who see Mr. Orban as a menace not only to his own country’s democracy but to Europe’s wider security because of his eagerness for close ties with Russia.
“Bashing Ukraine is the best thing you can do if you want to win points with Vladimir Putin,” said Peter Kreko, the director of the Political Capital Institute, a research group in Budapest that is often critical of Mr. Orban.
Despite being a member of the European bloc, which has put moving Ukraine toward the West at the heart of its joint foreign policy, Mr. Orban has repeatedly pushed in the other direction, tilting toward Russia whose authoritarian leader, Mr. Putin, he seems to view as a kindred spirit.
When Kiev announced a new language law late last year, designed to promote the use of Ukrainian and reduce Russia’s influence, Hungary retaliated by vowing to block Ukraine’s aspirations to forge closer ties with the European Union and NATO, undermining the goals of two organizations to which Hungary itself belongs.
As part of its outreach to the Hungarian diaspora, Budapest has set up a host of charities and foundations to provide financial and other support. The most visible of these, the Egan Ede Foundation, has provided thousands of ethnic Hungarians living in western Ukraine with cash grants to support their businesses.
In response, Ukraine’s internal security agency, known as the S.B.U., recently opened a criminal case against the foundation for promoting separatism.
Mr. Babek, Berehove’s mayor, said the real problem is not that Hungary offers so much financial and other help, but that Ukraine offers so little. When the town wanted to erect a statue to a revered Ukrainian writer, Taras Shevechenko, it spent years trying to raise money in Ukraine; it eventually got the bronze tribute finished after Hungary agreed to cover half the cost.
The biggest beneficiary of Hungarian money in Berehove is the Ferenc Rakoczi II Transcarpathian Hungarian Institute, which occupies the town’s largest building, a grand former courthouse built during the Austro-Hungarian Empire.
The institute’s rector, Idiko Orosz, had nothing but praise for Mr. Orban, who visited the institute in 2013 and pledged financial support, and for his Fidesz party. “It supports us so we support it,” she said.
She is particularly grateful to Fidesz for its help in protesting restrictions on the use of languages other than Ukrainian.
Hungarian-speakers living in Ukraine, she said, are not like the foreign immigrants whom Mr. Orban rails against constantly in Hungary, but are more like Native Americans who suddenly found their homeland taken over by strangers.
“We stayed at home; they came to us, not us to them,” she said, noting that her grandmother was born in Czechoslovakia and her mother in Hungary, while she was herself born in the Soviet Union. “None of us moved anywhere.”