In 757, a joint Tang-Huige army recaptured Chang'an and then the eastern capital Luoyang, forcing An Lushan's son and successor An Qingxu to flee to Yecheng. Tang forces put Yecheng under siege, and Li Siye, one of the Tang commanders at the siege, made Duan the prefect of Huai Prefecture (懷州, in modern Jiaozuo, Henan) to be responsible for logistics—the shipping of food supplies from the area to the army at Yecheng. In spring 759, Li Siye died in battle during the siege. The Anxi army supported Li Siye's subordinate Lifei Yuanli () to take over the command, and Emperor Suzong agreed. Duan remained as Lifei's deputy. Subsequently, at Duan's request, Li Siye's casket was sent to Hezhong (河中, in modern Yuncheng, Shanxi), where it was buried in grand ceremony at Duan's expense. This touched Lifei greatly, and he recommended Duan for a promotion in rank. In 762, while a number of armies were at Hezhong, including the Anxi army, Lifei was killed in an army mutiny, along with many other officers, but the soldiers respected Duan and did not dare to harm him. Subsequently, Bai Xiaode () was put in command of the Anxi army, and Duan remained as Bai's deputy. This continued after Bai was made the military governor of Fufang Circuit (鄜坊, headquartered in modern Yan'an, Shaanxi).