The plan for the fence — coming from Hungary, a former Communist country that was itself once behind the Iron Curtain — was also criticized by the United Nations refugee agency and the European Union. “We have only just torn down walls in Europe; we should not be putting them up,” said Natasha Bertaud, a spokeswoman for the European Commission. While member countries have the right to secure their borders, Ms. Bertaud emphasized that they could not flout international law by, for example, turning away migrants who are entitled to protection.

Nevertheless, Hungary has insisted that building the fence is legally within its rights, and that it is necessary to help it meet a serious migration challenge. Last year, the country received 41,215 applications for asylum, including 20,910 from citizens of Kosovo, 8,560 from Afghanistan and 6,630 from Syria, according to data from Eurostat. That was 7 percent of the total asylum applications received by the 28 members of the European Union.

It is unclear whether the criticism will deter Viktor Orban, Hungary’s populist prime minister, whom Washington and Brussels have accused of employing authoritarian tactics. Mr. Orban is one of Europe’s most outspoken critics of illegal immigration, linking immigrants to terrorism and warning that they are undermining Hungarians’ livelihoods.

The Hungarian government announced plans in April for a public consultation on immigration, including sending a questionnaire to eight million citizens ages 18 and over asking whether mismanagement of the immigration issue by Brussels had increased terrorism and whether they would support detaining immigrants who entered the country illegally at their own expense. That provoked an angry reaction from some members of the European Parliament. Cecilia Wikström, a liberal member from Sweden, wrote on Twitter that Mr. Orban was transforming Hungary into a “mini-Russia.”