Millions of tons of grain held hostage by war in the ports of Ukraine appear to be inching closer to a world that desperately needs food.

Three days after striking a deal with Russia to liberate the grain, Ukrainian laborers are laying the groundwork for shipments at the port of Odesa and others to markets overseas, Ukrainian officials say. And an attack by Russia on a military target at the Odesa port does not appear to have slowed the efforts.

But it is no small job.

Ukraine is often called the breadbasket of the world because of the robust output of its farms, but for its wheat and other grains to make it to a waiting world, it had to be transported to the country’s ports and then onto waiting ships.

That all ground to a halt when Russian forces poured over the Ukrainian border on Feb. 24. When Russia also deployed warships along Ukraine’s Black Sea coast, Ukraine mined the waters, deterring a naval attack, but also making the ports unusable for commercial shipping.

Over the weekend, officials said they were getting the gear back in motion.

“We continue technical preparations to launch the export of agricultural products from our ports,” Ukraine’s infrastructure minister, Oleksandr Kubrakov, said on Facebook.

Ukrainian seaports officials said they were getting the ports of Odesa, Chornomorsk and Pivdennyi ready for shipping to resume. “We inform you that the arrival and departure of ships to the specified seaports will be carried out by forming a caravan, which will be accompanied by the lead ship,” the Ukrainian Seaports Authority said in a statement.

At first, Russia denied having anything to do with the attack in Odesa, according to Turkey, which helped broker the deal. Then on Sunday, the Kremlin claimed it was hitting a military target.

“Kalibr missiles destroyed Odesa port’s military infrastructure, sending a Ukrainian military boat to the Kyiv regime’s favorite address in a precision strike,” the Russian foreign ministry spokeswoman, Maria Zakharova, said on Telegram.

Four Russian long-range missiles were fired and Ukrainian air defenses shot down two of them, Ukraine’s military said.

With the grain in effect blockaded, many countries, especially in Africa, were already experiencing food disruptions, with far worse feared.

On Sunday, Moscow sent its foreign minister, Sergey V. Lavrov, on a four-day trip to Africa to make Moscow’s case that the West is to blame for the shortages, not Russia. He said poorer countries were being victimized by wealthier ones.

“We know that the African colleagues do not approve of the undisguised attempts of the U.S. and their European satellites to gain the upper hand, and to impose a unipolar world order to the international community,” Mr. Lavrov wrote in an article published in newspapers in the four countries he was visiting: Egypt, Ethiopia, Uganda and the Republic of Congo.

An agreement to open the port to grain exports took months of negotiation between the warring nations, and at times appeared as if it would never happen.

When it finally did, on Friday, the ink was barely dry before Russia launched an attack on the port at Odesa, raising fears that the deal might collapse before it even started.

But the agreement appeared to be holding.

Ukraine’s ambassador to the United States, Oksana Markarova, said Sunday that her country would “do everything in order to perform and fulfill our part of the deal” and “feed the world.”

But Moscow, she protested, was not operating in good faith, while “our farmers are even planting and harvesting under the fire.” The parties had agreed that the vessels and port facilities used for grain operations would be safeguarded from hostilities.

Under the agreement, Ukrainian captains will steer vessels carrying grain out of port, and a joint command center with officials from Ukraine, Russia, Turkey and the United Nations will be set up in Istanbul to monitor the flotillas’ movements.

The ships will head into Turkish waters to be inspected by officials, then deliver their cargo around the world, returning for another inspection before heading back to Ukraine to satisfy a Russian demand that returning ships not carry weapons to Ukraine.