LONDON — Hungary went further than most of its neighbors last year to keep fleeing foreigners out of the country: It built a more than 100-mile-long razor-wire border fence and in a strongly criticized practice, still sends refugees who entered the country illegally to prison.

Human rights organizations such as Amnesty International condemned the country for showing "blatant disregard for its human rights obligations." The Hungarian government, however, did not seem to really care.

But now, the country has realized it actually needs more foreigners.

Faced with a severe labor shortage, the government is considering plans to invite non-E.U. "guest workers" to live in the country. "Guest workers" are usually allowed to stay and work in a country for a certain number of years but do not hold citizen rights.

Economics minister Mihály Varga has supported demands voiced by the country's Confederation of Employers and Industrialists to allow "hundreds of thousands of migrants from countries outside of the E.U." into Hungary, according to Austrian newspaper Die Presse. Estimates predict that the nation will need tens of thousands of migrants to make up for its labor shortage and to prevent negative economic repercussions. But the draft proposal specifies that the country wants "skilled, culturally integrable guest workers" — most likely implying that Muslims are not welcome.

Experts who study the country think that the government is trying to avoid a public backlash over trying to attract foreigners by excluding those it considers not "culturally integrable."

"They know it will be a hard sell to the Hungarians, given the way the government has staked its legitimacy on being nativist and xenophobic, suggesting that every foreign person who enters the country takes a job away from a native-born Hungarian," said Holly Case, a Brown University professor focusing on Eastern Europe who added that she did not think the country's "guest worker" plans would succeed.

"Based on what's happened thus far, I think if skilled younger workers have a choice between Hungary and other countries where the xenophobic rhetoric has not been so shrill, they will go elsewhere."

"If migrants ended up earning higher wages it is likely that tensions could increase," said her colleague Boldizsár Nagy, an associate law professor in Budapest.

Hungary's labor shortage had long been anticipated: Each year, Hungary loses young workers to other countries in the European Union, such as Germany or France, where wages are much higher. Restaurants and hotels especially have long been struggling to find Hungarians willing to stay.

"Many young Hungarians simply do not see a future for themselves in Hungary," Case said. "The government has not managed to make staying attractive, in spite of all their nativist 'Hungary for the Hungarians' rhetoric."

Moreover, birth rates in the country have been low for decades. Consequently, as in much of Eastern Europe, the nation's population is declining — and the share of older and retired people among the total population is increasing.

Law professor Nagy said that other factors played into Hungary's current labor shortage, as well: "Differences in housing prices between the east and west make it difficult for workers to move within the country."

Other European countries, such as Germany, face a similar problem, which is why German Chancellor Angela Merkel often referred to the possibility that young refugees could make up for a lack of skilled workers in the country and prevent the collapse of its pension system. Whether Germany will become a role model in that regard is uncertain. Since last year, only 30,000 refugees have found jobs — out of more than 1 million arrivals.

Hungarian Prime Minister Viktor Orban has chosen a different course: He supported programs aimed at attracting non-Muslim skilled workers to the country while condemning the influx of refugees and provoking strong rebukes from other E.U. leaders for comments that some considered xenophobic.

"We shouldn’t forget that the people who are coming here grew up in a different religion and represent a completely different culture. Most are not Christian, but Muslim. ... That is an important question, because Europe and European culture have Christian roots," Orban wrote in an op-ed published in September.

Calling Orban's behavior an example of "borderline political communication," Gabor Bernath, a researcher at the Hungarian Academy of Sciences, said that the prime minister's actions were also highly contradictory. "Just one year ago, Orban said [in front of] Arab investors: In Hungary, 'the culture of respect' still dominates."

The Hungarian government's balancing act will most likely become more apparent in the coming months: Although the country's Economics Ministry is preparing to sell the idea of coming to Hungary to potential migrants, Orban still plans to go a head with a controversial referendum scheduled for October. Voters will be able to decide whether the European Union should be allowed to send refugees to their country.

Most likely, Hungarians will vote no.

A previous version of this post described Nagy both as a law and philosophy lecturer. He is an associate law professor, and he does not believe that xenophobia would stop migrants from coming to Hungary.

Read more: