Bulgaria, Hungary, Poland, Romania and Slovakia cited concerns that grain from Ukraine meant to be exported to other countries had ended up in their local markets, which was pushing down prices for local farmers.
European Commission vice president Valdis Dombrovskis tweeted that the EU executive had reached "an agreement in principle" with the five "to address concerns of both farmers in neighbouring EU countries and Ukraine".
He said the deal included "safeguard measures" for four products - wheat, maize, rapeseed and sunflower seed. He did not provide any further details.
The deal also includes a support package worth €100 million ($110.25 million) for local farmers, Dombrovskis said.
Ukrainian President Volodymyr Zelenskiy said he had spoken on Friday to Charles Michel, President of the European Council, to raise concerns over what he called a destructive ban on exports of agricultural products.
"This gives the Kremlin dangerous hope, the hope that in our common European home someone's wrong decisions can prevail over common interests," he said in a video address.
The five countries became transit routes for Ukrainian grain that could not be exported through the country's Black Sea ports because of Russia's invasion.
Bottlenecks then trapped millions of tonnes of grains in countries bordering Ukraine, forcing local farmers to compete with an influx of cheap Ukrainian imports that they said distorted prices and demand.
European Commission President Ursula von der Leyen said the deal "preserves both Ukraine's exports capacity so it continues feeding the world, and our farmers' livelihoods".