After Russia's invasion blocked some Black Sea ports, large quantities of Ukrainian grain, which is cheaper than that produced in the European Union, ended up staying in Central European states due to logistical bottlenecks, hitting prices and sales for local farmers.
The issue has created a political problem for Poland's ruling nationalist Law and Justice (PiS) party in an election year as it has angered people in rural areas where support for PiS is usually high.
"We are aware of Poland and Hungary's announcements regarding the ban on imports of grain and other agricultural products from Ukraine," a spokesperson for the European Commission said in an emailed statement.
"In this context, it is important to underline that trade policy is of EU exclusive competence and, therefore, unilateral actions are not acceptable."
"In such challenging times, it is crucial to coordinate and align all decisions within the EU," the statement added.
Polish government spokesman Piotr Muller told state-run news agency PAP the government was in constant contact with the European Commission about the issue, and that the ban was possible due to a security clause.
Poland and Hungary have been embroiled in long-running conflicts with Brussels over issues including judicial independence, media freedoms and LGBT rights, and both have had funds withheld due to concerns over the rule of law.
Ukraine's farm minister Mykola Solsky talked to Hungarian counterpart Istvan Nagy on Sunday and underlined that unilateral decisions were unacceptable, the Ukrainian farm ministry said in a statement. The two agreed to talk again soon, it said.
The ministry said on Saturday that the Polish ban contradicted existing bilateral agreements on exports, and called for talks to settle the issue.
Meanwhile, Bulgaria's Agriculture Minister Yavor Gechev said the country was also considering a ban on Ukrainian grain imports, local agency BTA reported on Sunday.
The Polish ban, which came into effect on Saturday evening, will also apply to the transit of these products through the country, the development and technology minister said on Sunday.
"The ban is full, including the ban on transit through Poland," Waldemar Buda wrote on Twitter, adding that talks would be held with Ukraine to create a system that ensures goods only pass through Poland and do not end up on the local market.
State-run Ukrinform news agency said Ukrainian and Polish ministers are due to meet on Monday in Poland and the transit arrangement would be the focus of the talks.
Poland's Agriculture Minister Robert Telus was quoted as saying on Sunday that the ban was necessary to "open the eyes of the EU to the fact that further decisions are needed that will allow products from Ukraine to go deep into Europe, and not stay in Poland."
The ban is due to last until June 30, the finance ministry said.
Ukraine normally exports most of its agricultural goods, especially grain, via its Black Sea ports, unblocked in July in line with an agreement between Ukraine, Turkey, Russia and the United Nations.
That accord is scheduled to expire on May 18 and Moscow indicated last week that it may not be extended unless the West removes obstacles to the export of Russian grain and fertiliser.
Around 3 million tonnes of grain left Ukraine every month via the Black Sea grain corridor while only up to 200,000 tonnes are moving to European ports through Polish territory, according to the Ukrainian ministry.
Solsky said at the weekend that 500,000 to 700,000 tonnes of various agricultural products cross the Polish border every month, including grain, vegetable oil, sugar, eggs, meat and other products.