WARSAW, April 16 (Reuters) - Unilateral action on trade by European Union member states is unacceptable, the bloc's executive said on Sunday, after Poland and Hungary announced bans on grain and other food imports from Ukraine to protect their local agricultural sectors.

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.