found out about the plot and prepared to counteract; once Wang's plot exposed itself, he executed Wang and eight other coconspirators, and the rest of the army did not dare to resist the subsequent move to Jing Prefecture. In 773, during a Tufan incursion, Ma suffered a battle loss at the hands of Tufan forces and was trapped outside the city, unable to enter. His subordinate Jiao Lingchen () fled back into the city and suggested that Duan close the city gates to get ready for the Tufan assault. Duan responded, "The Governor has not returned. We need to use all of our strength to fight the barbarians. How can we just seek to spare ourselves?" He then told Jiao, "According to military laws, the penalty for losing your commander is death. Have you forgotten that?" Jiao became fearful, and Duan sent him back out to fight Tufan forces, forcing them to withdraw and allowing Ma to return to the city. In 776, Ma grew deathly ill, and he made Duan acting military governor before dying. With the soldiers gathering to mourn Ma, Duan was apprehensive that some soldiers would use this opportunity to mutiny. He therefore took careful precautions while arranging Ma's mourning, ordering that Ma's family, officers, soldiers, and commoners be segregated in their mourning and arresting anyone who disobeyed the orders. When he received reports that the officers Shi Tinggan (), Cui Zhen (), and Zhang Jinghua () were plotting mutiny and planning to rise at Ma's funeral, he defused the situation by sending Shi to Chang'an to serve in the imperial guards and sending Cui and Zhang out of the headquarters to other posts. He was thus able to preserve the peace at the circuit without killing anyone. In 777, Emperor Daizong made Duan the military governor. It was said that while Duan was strict, he was also gracious and governed simply. He did not gather wealth, and he did not have concubines. Except for official gatherings, he did not feast. In 778, when there was another Tufan incursion, Emperor Daizong sent Duan, along with Guo Ziyi and Zhu Ci, to defend against the incursion. During Emperor Dezong's reign Emperor Daizong died in 779 and was succeeded by Li Kuo (as Emperor Dezong). By 780, the chancellor Yang Yan had become very powerful and, having been a close associate of Yuan Zai's, was intent on reviving