UNITED NATIONS, May 17 (Reuters) - The Ukraine Black Sea grain deal has been extended for two more months, in what U.N. Secretary-General Antonio Guterres hailed as "good news for the world," a day before Russia could have quit the pact over obstacles to its grain and fertiliser exports.

Turkish President Tayyip Erdogan announced the extension in a televised speech and it was later confirmed by Russia, Ukraine and the United Nations.

The flow of ships through the corridor had been grinding to a halt during the last few days with the deal set to expire on Thursday.

"The continuation is good news for the world," the U.N.'s Guterres told reporters on Wednesday.

The United Nations and Turkey brokered the Black Sea deal for an initial 120 days in July last year to help tackle a global food crisis that has been aggravated by Moscow's invasion of Ukraine, one of the world's leading grain exporters.

Moscow had initially appeared unwilling to extend the pact unless a list of demands regarding its own agricultural exports was met.

"This is a chance to help ensure global food security, not in words, but in deeds. First and foremost, to help the countries most in need," Russia's foreign ministry said, confirming the extension.

"Our principled assessment of the Istanbul agreements of July 22, 2022, has not changed and the distortions in their implementation should be corrected as soon as possible."

While Russian exports of food and fertiliser are not subject to Western sanctions imposed following the February 2022 invasion of Ukraine, Moscow says restrictions on payments, logistics and insurance have amounted to a barrier to shipments.

Russia's UN ambassador, Vassily Nebenzia, said the deal was extended because "we still do not lose hope that the problems that we are raising will be sorted out."

UN chief Guterres said outstanding issues remain but that representatives of Russia, Ukraine, Turkey and the United Nations would keep discussing them.

"Looking ahead, we hope that exports of food and fertilizers, including ammonia, from the Russian Federation and Ukraine will be able to reach global supply chains safely and predictably," Guterres said.

The United States has rejected Russia's complaints. U.S. Ambassador to the U.N. Linda Thomas-Greenfield said last week: "It is exporting grain and fertilizer at the same levels, if not higher, than before the full scale invasion.

EXTENSION WELCOMED BY UKRAINE

Ukraine also welcomed the extension but a senior official said Russia must not be allowed to sabotage the agreement and must stop using food "as a weapon and blackmail."

"We welcome the continuation of the Initiative, but emphasise that it must work effectively," Deputy Prime Minister Oleksandr Kubrakov said on Facebook.

The extension helped to drive down grain prices on Wednesday with Chicago wheat futures and corn futures both falling by around 4%.