Warring sides in Yemen have agreed to a ceasefire in the flashpoint port city of Hodeidah and will withdraw all troops “within days”, marking a key breakthrough in the first peace talks in two years.

United Nations chief Antonio Guterres announced the agreement at the end of landmark talks in Sweden on Thursday, calling it “an important step” and “real progress towards future talks to end the conflict”.

​Yemen’s foreign minister and a leader in the rival Houthi rebel group then shook hands in a highly symbolic gesture that has raised hopes for progress on ending the near four-year war.

Bringing a halt to fighting in Hodeidah had been a key aim going into the UN-sponsored talks, which began a week ago in the Swedish town of Rimbos. Around 80 per cent of Yemen’s food supplies come through the city’s port. Humanitarian groups had warned that continued fighting there would cause a famine in which as many as 13 million could starve to death.

Mr Guterres said the United Nations would play a “leading role” in supervising the Red Sea port, which is currently controlled by the rebels. He said all sides would withdraw from the area “within days”.

“There is a ceasefire declared for the whole governorate of Hodeida in the agreement and there will be both from the city and the harbour a withdrawal of all forces,” he said at the closing ceremony of the talks.

“In the harbour the UN will assume a very important monitoring role and in the city the order will be maintained by the local forces.”

A “mutual understanding” on Yemen’s third city of Taiz, the scene of some of the most intense battles in the conflict, would also be part of the deal. There, humanitarian corridors will be open to the city, which had been intermittently under crippling Houthi siege during the conflict.

Mr Guterres also announced a new round of talks would take place at the end of January.

“I am glad that we made real progress here in Sweden,” he said, describing the deal as a “big step” for the Yemeni people. “This is just the beginning … We have agreed to engage in the discussions on a negotiating framework in the next meeting at the end of January,” he added.

The news came as Jeremy Hunt, the UK foreign secretary, flew to Sweden to join the final day of the talks held in the town of Rimbo, where he met with the internationally recognised Yemeni government and representatives of the Houthi rebels.

“Yemen is the world’s worst humanitarian catastrophe, and these peace talks represent the best opportunity in years to move towards the political solution the people of Yemen urgently need,” Mr Hunt said from Sweden.

Michael Aron, the UK’s ambassador to Yemen, was also present. He tweeted a photo of the historic handshake between the warring Yemeni factions writing “the moment we have all been waiting for”.

Yemen has been ripped apart by a ruinous three-and-a-half-year war that has sparked the world’s worst humanitarian crisis in terms of numbers and pushed the impoverished country to brink of a devastating famine.

Fighting first erupted in the spring of 2015 after the Iran-backed Houthi rebel group swept control of the country ousting the recognised president Abdrabbuh​ Mansour Hadi.

Malnutrition centre in Mukalla, Yemen provides care for children suffering hunger and famine

Saudi Arabia and its Gulf allies launched a bombing campaign to reinstate Mr Hadi, fearing the encroachment of Iran’s influence on its borders. The latest battleground has been around Hodeidah, which is currently home to over 300,000 people.

This week the UN announced that the conflict has meant a staggering 20 million people in Yemen are now going hungry, which is well over half the population and a 15 per cent increase from last year.

Of that number, some 250,000 people are currently starving to death, the UN added.

News of the agreement was welcomed by the UAE, a major part of the Saudi-led coalition.

Anwar Gargash, the UAE’s minister of state for foreign affairs, wrote on Twitter: “Encouraging news today from Sweden. Important political progress made including the status of Hodeida. The Coalition & Yemeni forces’ military pressure enabled this significant breakthrough.”

However Saudi Arabia’s ambassador to Yemen struck a more cautious tone, saying that the ceasefire deal was dependent on a Houthi withdrawal from Hodeidah “as well as Taiz, and the release of thousands of detainees and prisoners”. Yemen’s foreign minister, Khaled al-Yamani, also said the deal remains “hypothetical” until rebels pull out of the city.

Lorraine Marulanda, head of the Middle East region and North Africa for the British Red Cross, said the agreement was “an extremely welcome and important step”.

She added: “Even before the war, Yemen relied on over 90 per cent of imports of food and other important commodities to survive. Hodeida is a key port. It is hoped that a cessation in hostilities will mean that much needed food, medicine and other aid will be able to make its way through the port to those most in need.”

But despite a swell of optimism over the agreement, many close observers of the Yemen saga were sceptical it would evolve into a permanent settlement.

One international official, who has worked for years on resolving the Yemen conflict, said the Saudi and UAE-led coalition was likely giving in on the port in order stave off harsh punishments by US lawmakers against Crown Prince Mohammed bin Salman over the Yemen war and the murder of journalist Jamal Khashoggi. In the long run, anything short of victory over the Houthis will damage Prince Mohammed’s ability to rule a kingdom already wary of him.

“Someone like him cannot lose face, and he’s willing to put up even more money to come up with something that makes him look like the winner,” said the official, who spoke on condition of anonymity because he continues to work on sensitive Middle East matters. “If he’s not really pressured to do something, he won’t stop anything.”