Zhang Jun continued to serve as chancellor after Emperor Xizong died in 888 and was succeeded by his brother
Emperor Zhaozong, who was supported by Yang Fugong. However, after Emperor Zhaozong became emperor, both Zhang and fellow chancellor
Kong Wei advocated a suppression of eunuch power. Emperor Zhaozong agreed, and, as he knew that Yang resented Zhang, trusted Zhang further with his plans of suppressing Yang's power. Zhang often compared himself to the great
Jin dynasty (266–420) Xie An and the great Tang chancellor
Pei Du. Further, under Zhang's advocacy that the imperial government needed an army of its own, Emperor Zhaozong created an imperial army drawn from the people from Chang'an region, of some 100,000 strong. In 890, after Li Keyong failed in his campaign to attack
Helian Duo the defender of Yun Prefecture (雲州, in modern
Datong,
Shanxi), Helian, Li Keyong's main rival
Zhu Quanzhong the military governor of Xuanwu Circuit (宣武, headquartered in modern
Kaifeng,
Henan), and
Li Kuangwei the military governor of Lulong Circuit (盧龍, headquartered in modern
Beijing), all submitted petitions to Emperor Zhaozong asking him to declare Li Keyong a renegade and declare a general campaign against Li Keyong. When Emperor Zhaozong requested opinions from imperial officials, most opposed, including the chancellors
Du Rangneng and
Liu Chongwang, but Zhang and Kong, who wanted to try to use this as an opportunity to reassert imperial power, advocated for the campaign against Li Keyong and to then use that power to suppress the eunuchs, strenuously advocated for the campaign. Emperor Zhaozong, despite misgivings, agreed, and he put Zhang in overall command of the operations, assisted by the official Sun Kui (). As Zhang was leaving, he privately stated to Emperor Zhaozong, "Let me first eliminate the external threat for Your Imperial Majesty, and then eliminate the internal threat." These words nevertheless became known to Yang, who became apprehensive of Zhang. Further, when Yang held a feast for Zhang to send him off, Zhang refused to drink when Yang offered wine. Yang sarcastically stated, "Lord Chancellor, you are holding the imperial sword. Why are you so hesitant?" Zhang responded, "Let me first destroy the bandits, and they you will see why I am hesitant." This aggravated Yang further, and he thereafter tried to hinder the campaign. Initially, the imperial government appeared to have the upper hand, as Zhang's imperial army was supplemented by armies sent by Zhenguo (鎮國, headquartered in modern
Weinan,
Shaanxi), Jingnan (靜難, headquartered in modern
Xianyang,
Shaanxi), Fengxiang (鳳翔, headquartered in modern
Baojing,
Shaanxi), Baoda (保大, headquartered in modern
Yan'an,
Shaanxi), and Dingnan (定難, headquartered in modern
Yulin, Shaanxi) Circuits, including Zhenguo's military governor
Han Jian. Zhu was also attacking Li Keyong's domain from the southeast, and Helian and Li Kuangwei from the northeast. Further, just as Zhang's army was launched, Li Keyong's brother Li Kegong () the military governor of Zhaoyi Circuit (昭義, headquartered in modern
Changzhi,
Shanxi), was assassinated by his own officer An Jushou (), who in turn was killed by another officer, Feng Ba (), who surrendered the circuit capital Lu Prefecture () to Zhu Quanzhong's officer Zhu Chongjie (). Hearing the news, Emperor Zhaozong and Zhang, not wanting Zhaoyi to fall into Zhu Quanzhong's hands, commissioned Sun as the military governor of Zhaoyi and ordered him to report to Zhaoyi immediately. As Sun was advancing to Lu Prefecture, however, he took few precautions against a surprise attack. Li Keyong's adoptive son
Li Cunxiao made a surprise attack on Sun's procession, capturing him. (When Sun subsequently would not submit to Li Keyong, Li Keyong killed him.) This demoralized the imperial army, and subsequently, with Li Cunxiao putting Lu Prefecture under siege, the Xuanwu forces withdrew from Zhaoyi. Meanwhile, Li Keyong's other adoptive sons
Li Cunxin and
Li Siyuan defeated Li Kuangwei and Helian, forcing them to withdraw as well, leaving Zhang's forces alone against Li Keyong himself. The imperial forces engaged Li Keyong's at Fen Prefecture (汾州, in modern
Lüliang,
Shanxi). Han tried to take the initiative by making a surprise night attack on Li Cunxiao, but Li Cunxiao took precautions, and Han's attack was not successful. Thereafter, without battling, the Jingnan and Fengxiang forces suddenly disengaged and left the imperial camp. The imperial forces, demoralized, collapsed. The Hedong forces gave chase, catching Zhang at Jin Prefecture (晉州, in modern
Linfen,
Shanxi). Zhang tried to engage Hedong forces, but was again defeated. After this defeat, the Baoda and Dingnan forces also fled, leaving Zhang's own imperial forces, along with Han's Zhenguo forces and some Xuanwu forces sent by Zhu Quanzhong. Zhang defended Jin Prefecture, and Li Cunxiao put it under siege. After three days, Li Cunxiao decided that no benefit could come from capturing a chancellor and slaughtering imperial forces, and therefore lifted the siege to allow Zhang and Han to flee, and they did so. As they did, it was said that the imperial army, in effect, disintegrated. Li Keyong submitted harshly-worded petitions to Emperor Zhaozong, outwardly offering to submit himself to judicial proceedings, but clearly accusing Zhang of wrongly attacking him. Emperor Zhaozong tried to placate Li Keyong by demoting Zhang to be the military governor of Wuchang Circuit (武昌, headquartered in modern
Wuhan,
Hubei), and Kong to be the military governor of Jingnan Circuit (荊南, headquartered in modern
Jingzhou,
Hubei, not the same circuit that initially joined the imperial cause against Li Keyong), and restoring Li Keyong's titles. When that failed to placate Li Keyong, Emperor Zhaozong further exiled both Zhang and Kong—in Zhang's case, to be the prefect of Lian Prefecture (連州, in modern
Qingyuan,
Shandong), and then to be the census officer at Xiu Prefecture (繡州, in modern
Guigang,
Guangxi). == First retirement ==