After weeks of delicate talks, Russia and Ukraine each signed agreements with Turkey and the UN in Istanbul, raising hope of easing the hunger crisis after the first major diplomatic breakthrough of the five-month war.
Western powers reacting to the deal said they would be watching to ensure promises were turned into action.
International aid agencies and diplomats expect grain to start fully flowing by the middle of August, but even with the delay grain prices fell on Friday.
"Today, there is a beacon on the Black Sea: a beacon of hope, a beacon of possibility, a beacon of relief, in a world that needs it more than ever," said UN Secretary General Antonio Guterres at a signing ceremony on Friday.
Mr Guterres said the deal would clear the way for grain shipments from three Ukrainian ports, Odesa, Chernomorsk and Yuzhny, stabilising runaway prices and restoring one of the world's most important grain routes.
A co-ordination centre will be set up in Istanbul to manage Black Sea traffic, which will be subject to joint controls to check that cargo ships are not carrying weapons. Ukraine said no Russian inspectors would come within its waters.
There was no immediate word on any military escort but Russia said it was up to Ukraine to ensure safe passage through minefields and promised it would "not take advantage of the fact that the ports will be cleared and opened."
The package deal also includes an agreement on getting Russian food and fertilisers to world markets, Mr Guterres said.
Market analysts said questions would remain about how well Ukraine's ports are functioning following bombardment by Russian forces, and about the quality of the grain held at the harbours.
Western diplomats welcomed the deal but said they would be watching Russia's movements closely, and are expecting an implementation period before cargo ships start moving again.
Guy Platten, secretary general of the International Chamber of Shipping, said the deal was a "long-needed breakthrough" but that ensuring crew safety in highly sensitive waters would be crucial to getting exports moving quickly.
The struggle for Ukraine's southern coast, and the laying of naval mines which the two sides blamed on each other, had brought shipping traffic to a standstill and left about 20 million tonnes of grain stranded in Ukrainian silos.
Food and fertiliser prices mounted and the UN said 47 million people could face severe food scarcity because of the obstruction of the vital shipping lane, while alternative land and river routes proved only a partial substitute.
The EU accused Russia of engineering the crisis by bombarding Ukrainian grain warehouses, but Moscow said, in a counter-narrative rejected in western capitals, that sanctions were fuelling the crisis.
"With the text agreed on today, we will contribute together to prevent the danger of famine that awaits billions of people all over the world," said Turkish President Recep Tayyip Erdogan.
After what he called an "intensive and arduous process" to strike a deal, Mr Erdogan urged Russia and Ukraine to remain at the negotiating table because "there will be no winner in this war".
Ukraine described the arrangement as two separate, mirroring deals signed by Russia and Ukraine, meaning no direct deal between the two of them. Representatives of the warring parties went up separately to sign the documents in Istanbul.
The signing ceremony was delayed briefly by disputes about the arrangement of flags around the table and on signboards for the ceremony, and Ukraine's refusal to put its name on the same document as the Russians. The two sides eventually inked separate but identical agreements after the flags were moved and the signboards replaced.
Nonetheless, the deal represents the first major diplomatic success in Russia-Ukraine talks since the war began, after tentative peace talks mediated by Turkey in March failed to bring a stop to the fighting.
Dr Anwar Gargash, the UAE President's diplomatic adviser, hailed it as a positive step that underlined the need for a political solution to the crisis.
"The grain export agreement signed by Moscow and Kiev in Istanbul is a positive step in the protracted war. This is a positive achievement for Turkish diplomacy, and it reaffirms the need to reach a political solution to the crisis. Escalation is not in the interest of the international system and an urgent peaceful solution is necessary," Dr Gargash wrote on Twitter.
"This deal offers hope that a global hunger crisis can be averted," said Colm Markey, a farmer and member of the European Parliament's agriculture committee.
Sarah Champion, a British MP and chair of a parliamentary development committee, told The National she was cautiously optimistic over what "should be a big step forward in helping to tackle the global hunger crisis" — but said the UK should still increase funding for people facing hunger and malnutrition.
"Countries must act quickly to export the backlog of food exports from Ukraine so food can reach the world's poorest communities," she said. "But this deal alone won't solve the problem."
Kremlin spokesman Dmitry Peskov said the looming food crisis meant it was “very important” to unblock the supply of fertilisers, food and grain to the world markets, while playing down the problem as "a relatively small amount of Ukrainian grain".
Ukrainian presidential aide Mykhaylo Podolyak vowed a Ukrainian “military response” to any provocations from Russia and said the Kremlin's representatives would not enter Ukrainian harbours. He said any necessary inspections of cargo ships “will be carried out by joint groups” in Turkish waters.
The five-month war is being fought across one of Europe's most fertile regions by two of the world's biggest producers of grain. Before the wall, almost all of the grain was shipped out of the region across the Black Sea.
Alternative routes were not entirely satisfactory, because river barges to Romania do not have the same capacity as Black Sea cargo ships, and rail wagons need unloading or replacing at the Polish border.
Chicago wheat fell more than 3 per cent on Friday on expectations of higher supplies from the Black Sea region as Russia and Ukraine are due to sign a deal to open ports for grain shipments.