What is the problem?
Ukraine is one of the world's biggest grain producers, but exports from its Black Sea ports ground to a standstill after the invasion. Russian warships patrol the waters and the two sides have blamed each other for laying naval mines.
The obstruction in a vital shipping lane led to a surge in global food prices and a shortage of grain that the UN fears will throw an additional 47 million people into severe food scarcity worldwide.
And Ukraine wants the grain out as much as others want it in, because it needs the money from exports and its farmers need to free up space for the next harvest.
What is the solution?
The UN and Turkey have been trying for weeks to broker a deal between Russia and Ukraine to reopen the Black Sea, culminating in the agreement signed on Friday.
The parties agreed to carry out joint checks on shipping - ensuring there are no weapons lurking among the grain cargoes - and establish a co-ordination centre in Istanbul to manage implementation of the deal.
There was no immediate word on any military escort or on de-mining the Black Sea, but Russia said it was up to Ukraine to ensure safe passage through its waters.
Russian Defence Minister Sergey Shoigu said Russia "will not take advantage of the fact that the ports will be cleared and opened... we have made this commitment".
Mykhailo Podolyak, a Ukrainian presidential adviser, said Russian officials would not enter the confines of Ukrainian ports and that any on-board inspections would be carried out in Turkish waters.
Any Russian provocation would be met with an "immediate military response," he 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. Another question is whether cargo ships will be able to get insurance for braving the Black Sea.
What are people saying about the deal?
Turkish President Recep Tayyip Erdogan said the parties would "contribute together to prevent the danger of famine that awaits billions of people all of the world" and said the deal could revive hopes of a negotiated peace.
UN Secretary-General Antonio Guterres described it as a beacon of hope and said the resumption of exports would avert "a true nightmare" for developing countries.
The European Union's top diplomat, Josep Borrell, said the agreement was "a step in the right direction... we call for its swift implementation."
Liz Truss, the UK's foreign secretary and one of two remaining candidates to be the next prime minister, said on Friday that Britain "will be watching to ensure Russia's actions match its words.
"To enable a lasting return to global security and economic stability, Putin must end the war and withdraw from Ukraine," she said.
Kremlin spokesman Dmitry Peskov said it was important to unblock the Black Sea, while playing down the problem as "a relatively small amount of Ukrainian grain". Russia said its Defence Minister Sergey Shoigu would be in Turkey to sign the agreement on Friday.
In Washington, State Department spokesman Ned Price said the US would welcome any agreement and applauded “the diligent work of our Turkish allies”, but said diplomats would focus on “holding Russia accountable for implementing this agreement.”
Janusz Wojciechowski, the EU commissioner in charge of agriculture, said Ukraine's position as a breadbasket might remain impaired even after the Black Sea is reopened, because the volume of grain it plants for next year may be reduced because of the war.
What about other ways of extracting grain?
There are alternatives to the Black Sea, but all of them are less satisfactory.
The rail route to Poland is slowed down by an accident of history — Ukraine and its EU neighbours use different widths of track, causing delays at the border. And Ukraine says relaxations to EU border checks have not gone far enough.
Belarus, whose railways would be compatible with Ukraine's, is an unsuitable partner because of its close alliance with Moscow, and EU officials have privately ruled out that option.
River barges down the Danube to Romania have also taken some of the strain but simply do not have the same capacity as Black Sea cargo ships.
In the meantime, rich countries have promised more than $14 billion in aid to ease immediate hunger and malnutrition, and said they plan to inspect grain in order to deter alleged Russian pilfering.