The two governments "agreed on the possibility" of transporting Ukrainian produce via the Danube to EU member Croatia, Ukraine's Foreign Minister Dmytro Kuleba said.
From Croatia, the food could be exported via the Adriatic Sea to the Mediterranean and the world market.
"We will now work on laying the most efficient routes to these ports and making the most of this opportunity," Mr Kuleba said.
"Every contribution to unlocking exports, every door opened is a real, effective contribution to world food security. Thank you to Croatia for the constructive help."
Moscow quit the Black Sea grain deal this month, saying the side of the bargain providing for Russian food and fertiliser exports had not been upheld.
It led to fears of a renewed global food crisis because Ukraine usually exports the largest share of its grain via Black Sea ports such as Odesa.
Alternatives exist including Romania's Danube ports and a railway route to Poland but none can handle the same volume as cargo ships.
"In the context of a possible global food crisis, Croatia has made its ports available for the export of Ukrainian grain and will continue to do so," Foreign Minister Gordan Grlic-Radman said.
Croatia also plans to host a conference in October on demining in Ukraine. Naval charges in the Black Sea are one of the reasons the route is dangerous for cargo ships.
UN Secretary General Antonio Guterres last week said food prices had already risen after Russia quit the grain deal.
The pact was brokered last year by the UN and Turkey and provided for safe passage for cargo ships on condition that both sides in the war could inspect them. Since withdrawing, Russia has attacked Odesa's harbour and withdrawn security guarantees to Black Sea shipping.