CAIRO — Yemen’s warring parties have agreed to a cease-fire in the crucial port city of Hudaydah, the United Nations chief said on Thursday, announcing the biggest step toward peace in years for a war that has produced the world’s worst humanitarian crisis.

The Saudi-led coalition and Houthi rebels have agreed to withdraw their forces from Hudaydah, the main conduit for humanitarian aid entering Yemen, and to implement a cease-fire in the surrounding province, Secretary General António Guterres told reporters.

He made the announcement in Rimbo, Sweden, at the end of a week of negotiations intended to pave the way for full peace talks. Amid smiles and handshakes, representatives from the two sides also agreed to a prisoner exchange involving as many as 15,000 people, and to allow a humanitarian corridor into the city of Taiz, Yemen’s third-largest city. They agreed to meet again in January.

The terms of the deal announced by Mr. Guterres were vague in places, with talk of a “mutual redeployment” to stop the fighting in Hudaydah, and a “leading role” for the United Nations in the city. The United Nations is due to oversee the withdrawal of all combatants from the city within 21 days, but there was little detail about how that will happen.