Chengdu late in 880 due to an attack by the major agrarian rebel Huang Chao, Du also fled and caught up with the emperor in Chengdu. When the chancellor Xiao Gou also served as the director of finances, Du, in addition to his duty at the ministry of defense, also served under Xiao in that capacity. Subsequently, he was also made Libu Langzhong (禮部郎中), a supervisory official at the ministry of rites, as well as an editor of imperial history. Thereafter, he was put in charge of drafting edicts, and was also made Zhongshu Sheren (中書舍人), a mid-level official at the legislative bureau. It was said that, at that time, as Emperor Xizong had to often issue edicts in monitoring the Tang forces' campaigns against Huang, many edicts had to be written quickly, and Du wrote effectively and efficiently. Emperor Xizong was happy about his abilities and made him the deputy minister of census (戶部侍郎, Hubu Shilang). After Emperor Xizong was able to return to Chang'an after Huang's defeat, Du was made the minister of rites (禮部尚書, Libu Shangshu), given the honorary title of Yinqing Guanglu Daifu (銀青光祿大夫), and created the Viscount of Jianping. Subsequently, he was made the minister of defense (兵部尚書, Bingbu Shangshu) and chief imperial scholar (翰林學士承旨, Hanlin Xueshi Chengzhi). In late 885, after the powerful eunuch Tian Lingzi got into a dispute with the warlord Wang Chongrong the military governor of Hezhong Circuit (河中, headquartered in modern Yuncheng, Shanxi) and tried to transfer Wang to another circuit, Wang and his ally Li Keyong the military governor of Hedong Circuit (河東, headquartered in modern Taiyuan, Shanxi) engaged the forces under Tian and Tian's allies Zhu Mei the military governor of Jingnan Circuit (靜難, headquartered in modern Xianyang) and Li Changfu the military governor of Fengxiang Circuit (鳳翔, headquartered in modern Baoji, Shaanxi). Wang's and Li Keyong's forces defeated those under Tian, Zhu, and Li Changfu, and approached Chang'an. Emperor Xizong fled to Xingyuan (興元, in modern Hanzhong), and initially, very few imperial officials followed, with Du being one of the few. Subsequently, Emperor Xizong made both him and another official who followed to Xingyuan, Kong Wei, chancellors, with the designation Tong Zhongshu Menxia Pingzhangshi (同中書門下平章事). As chancellor By this time, however, Zhu Mei had occupied Chang'an and declared Emperor Xizong's distant relative Li Yun the Prince of Xiang the new emperor, and it was said that few