Ukraine and Russia have signed "mirror" deals which will allow Kyiv to resume exports of grain through the Black Sea.
The agreement will allow millions of tonnes of grain, currently trapped in Ukraine by the war, to be exported.
The world shortage of Ukrainian grain since Russia's 24 February invasion has left millions at risk of hunger.
However, Kyiv refused to sign a direct deal with Moscow, and warned "provocations" would be met with "an immediate military response".
Both sides attended the signing ceremony in Istanbul but did not sit at the same table. Russia's Defence Minister Sergei Shoigu signed Moscow's deal first, followed by Ukrainian Infrastructure Minister Oleksandr Kubrakov signing Kyiv's identical agreement.
The deal - which took two months to reach - is set to last for 120 days, with a co-ordination and monitoring centre to be established in Istanbul, staffed by UN, Turkish, Russian and Ukrainian officials. It can be renewed if both parties agree.
The blockade of Ukraine's grain has caused a global food crisis with wheat-based products like bread and pasta becoming more expensive, and cooking oils and fertiliser also increasing in price.
The US called on Russia to act quickly, with White House spokesman John Kirby saying it was necessary "to prevent the world's most vulnerable from sliding into deeper insecurity and malnutrition".
Mr Shoigu told a news conference earlier the deal might allow "the solutions to start this process in the coming days".
"I'm talking not only about beginning the export of agricultural products from Ukrainian ports but clearly also work in this direction on the export of agricultural products and fertilisers from Russian ports," he added.
According to diplomats, under the terms of the deal:
Russia will not target ports while shipments are in transit
Ukrainian vessels will guide cargo ships through waters that have been mined
Turkey - supported by the United Nations - will inspect ships, to allay Russian fears of weapons smuggling
Russian exports of grain and fertiliser via the Black Sea will be facilitated.
UN Secretary General Antonio Guterres told the BBC's Orla Guerin it was probably the most important thing he had done in his time heading the international body.
"Today, there is a beacon on the Black Sea," he told the audience gathered in Istanbul. "A beacon of hope."
The bottlenecks on routes to export Ukraine grain
Pictures provide evidence of Russian grain theft
How much grain is stuck in Ukraine?
Just the prospect of unblocking more than 20 million tonnes of Ukrainian grain led to a 2% drop in wheat prices on Friday.
In his Friday night address, Ukraine's President Volodymyr Zelensky confirmed the country had about $10bn (£8.3bh) worth of grain to sell.
However, he also warned Moscow "could engage in provocations, attempts to discredit the Ukrainian and international efforts. But we trust the United Nations", saying it was up to the UN to guarantee the deal.
But Mr Guterres admitted to the BBC that the UN had no means of punishing Russia should it breach the deal - but added it would be "an absolutely unacceptable scandal and the whole international community would react in a very strong way".
Mr Shoigu had assured reporters after signing the deal that Russia had "taken on the obligations" under the deal, and they would "not take advantage of the fact that the ports will be cleared and opened".
Russia has always denied blockading Ukraine's ports - it blames Ukraine for laying mines at sea and Western sanctions for slowing Russia's own exports.
In a piece aimed at newspapers in Africa, Foreign Minister Sergei Lavrov blamed the West and Ukraine for the "absolutely groundless" allegations. He praised the "balanced position of the Africans regarding what is happening in Ukraine and around it".
Ukraine, however, says the Russian navy prevents it shipping grain and other exports and accuses Russian occupation forces of stealing grain from Ukrainian farms.
The grain export deal will also come as a big relief to the Horn of Africa, the BBC's Anne Soy says from Nairobi, Kenya. The region is currently facing serious food shortages caused by drought, and exacerbated by the Covid-19 pandemic, a rare locust invasion and the war in Ukraine.
Samantha Power, the US development agency's administrator, said the deal was "an extremely important piece of a puzzle" in solving the region's crisis.
Meanwhile, Turkey's President Recep Tayyip Erdogan - who has played a crucial role in negotiations - said he hoped the deal might be the first step towards bringing the war to an end.
"This joint step we are taking with Ukraine and Russia will hopefully revive the path to peace," he said.
Mr Guterres was less positive, saying: "At the present moment, I see no conditions for a peace process."