ISTANBUL—Officials from Russia, Ukraine and the United Nations planned to sign a deal to resume exports of Ukrainian grain via the Black Sea on Friday, Turkish and U.N. officials said, in an announcement that raised hopes of freeing food supplies trapped by the Russian invasion.

U.N. Secretary-General António Guterres landed in Istanbul on Thursday evening, a U.N. official said, adding that the parties involved had come to an agreement but cautioned that last-minute problems could still arise before they sign off on the deal, expected on Friday.

Russia didn’t immediately comment on the plans for a signing ceremony on Friday. Turkey’s and Russia’s presidents have sounded positive about the talks in recent days, as has a senior Ukrainian official.

Russia and Ukraine didn’t immediately comment on the plans for a signing ceremony on Friday. Turkey’s and Russia’s presidents have sounded positive about the talks in recent days, as has a senior Ukrainian official.

“Tomorrow in Istanbul, we will take the first step to solve the current food crisis with U.N. Secretary-General, Ukrainian & Russian delegations,” Turkey’s Foreign Minister Mevlut Cavusoglu said in a tweet Thursday.

An agreement could potentially free up about 18 million tons of wheat, corn and other supplies that war has prevented Ukraine from exporting, with the Russian invasion contributing to a rise in global food prices that U.S. officials said has sparked protests in 17 countries.

Ukraine’s foreign ministry confirmed that negotiations would resume in Turkey on Friday and that a document could be signed following the talks.

“The Ukrainian delegation will support only those decisions that will guarantee the security of the southern regions of Ukraine, the strong positions of the Ukrainian Armed Forces in the Black Sea, and the safe export of Ukrainian agricultural products to the world markets,” the ministry said in a statement.

In recent days, substantial differences remained among the warring parties over issues ranging from the demining of ports to safe passage for cargo vessels, Western officials said. U.N. and other officials didn’t say how those disputes were resolved. Should the governments reach a deal, enforcement will be key, and privately owned freighters, insurers and sea crews might be reluctant to handle cargoes from Odessa and other war-zone ports, given the threat of further attacks, according to the officials, grain traders and other industry experts.

Ukraine faces the challenge of how to store or export its coming summer harvest.

Photo: OLGA MALTSEVA/AFP/Getty Images

Both Russia and Ukraine have laid sea mines in the Black Sea that pose a hazard to the movement of any ships in the area. Military delegations from Russia and Ukraine disagreed in the talks in recent weeks over how the demining would take place, a U.S. official said.

Ukraine has also increased the number of mines near its ports in recent weeks to defend against possible Russian attacks, the official said.

Safe passage for ships handling food cargoes and procedures for searching private vessels to ensure they aren’t carrying military equipment are among the issues to be resolved, officials said. Beyond that, Ukraine has demanded international security guarantees to prevent a Russian attack once mines are removed.

“You still have to get the parties to address the demining and the unfettered access and movement for the vessels themselves,” said the U.S. official.

Russian, Ukrainian, Turkish and U.N. officials took part in grain-export talks in Istanbul earlier this month.

Photo: Turkish Defence Ministry/Associated Press

Russia is still seen as a potential spoiler, U.S. and other officials said, with Washington and Ankara trying to pressure the Kremlin to reach a deal and implement it.

“Turkey is pressing Russia to say this can’t be a zero nothing forever. And Russia, you’re not going to like the look if you make your own navy guys take back their own mines. That’s an admission of guilt,” the official said.

Russian President Vladimir Putin, meeting Turkey’s President Recep Tayyip Erdogan

on Tuesday, thanked him for his mediation and said that the talks had made progress. “Not all issues, however, have been resolved. But the fact that we have moved forward is already good,” Mr. Putin said, according to remarks shown on Russian television.

Meanwhile, skeptical U.S. officials this week pointed to recent Russian attacks on Ukrainian ports and grain-storage facilities as part of its war strategy.

“We are hoping for the best, but we have seen how Putin weaponizes food,” Jose Fernandez, the U.S. undersecretary of state for economic growth, energy and the environment, said on Wednesday.

The U.K. government has been in contact with Lloyd's of London insurance market to discuss how the commercial shipping that will transport the grain will be insured. “Those talks are ongoing but they seem to be progressing reasonably well,” said one official briefed on the process. However, issues such as whether ports needed to be demined remains, the official said.

To nudge the talks forward, the U.S. and the European Union have in recent days clarified that financial sanctions against Russia don’t pertain to food and agricultural trade. Clearing a path for Russia’s food and fertilizer exports is part of the framework for a broader deal on grain exports put forward by Mr. Guterres.

Russia and Ukraine have laid sea mines in the Black Sea. Cargo ships wait for port access near Constanta, Romania.

Photo: Andrei Pungovschi/Bloomberg News

The stakes of a potential agreement are high for the poorer nations that were Ukraine’s biggest customers. Much of the grain formerly exported via the Black Sea went to Asian countries and to Egypt, the world’s largest importer of wheat.

While grain prices have fallen from the highs they reached in the aftermath of the invasion, an increase in Ukrainian supply would ease pressure on prices.

Grain traders working in the region also expressed doubt that Russia would allow the grain exports while its military campaign continues to destroy Ukraine’s farms, roads, grain-storage facilities and other vital infrastructure necessary to export grain.

“To me, their objective is strangulation, somehow or another, of Ukraine. They’ve been stealing grain from the occupied areas,” said Jonathan Grange, a partner at Sunstone Brokers, an agricultural-commodities brokerage working in Ukraine and the Black Sea region.

Ukraine exported about two million metric tons of grain in June overland and via smaller ships leaving the Danube River into the Black Sea, according to Ukrainian officials. That maritime route opened up this month after Ukraine’s military retook strategic Snake Island from Russia, which occupied it soon after the invasion began in February.

In addition to up to 18 million tons of grain currently trapped in Ukraine as a result of the invasion, there is also the challenge of how to store or export the country’s coming summer harvest of an estimated 65 million tons, according to Mr. Grange.

“We are desperately looking at those negotiations,” said Ivan Kriuchkov, a director at Ukrainian agribusiness IMC. “If the ports don’t open, where do we put all our grain?”

Write to Jared Malsin at jared.malsin@wsj.com, William Mauldin at william.mauldin@wsj.com and Alistair MacDonald at alistair.macdonald@wsj.com