Gradually however he despaired of any prospects for victory, and began negotiations with Abu Ahmad. He was accused of treason and almost lynched by the city's defenders, and was saved only by the intervention of Musta'in. Eventually, Musta'in agreed to surrender and abdicate in favour of Mu'tazz in January 866.[1][8][9] Muhammad remained in his position and held his offices until his death in November 867.[1]