Later, when
Gao Shi () oversaw the office of imperial censors (御史臺,
Yushi Tai), he had Wang Hui recalled to Chang'an to serve as a supervising censor
Shi Yushi Zhiza (), as well as
Zhifang Yuanwailang (), a low-level official at the ministry of civil service affairs (吏部,
Libu). From that latter position, Wang was later promoted to
Kaogong Langzhong (), a supervisory official at the ministry of civil service affairs. The chancellor
Xiao Fang particularly respected Wang for his administrative abilities. Wang was later made
Sifeng Langzhong (), still a supervisory official at the office of civil service affairs, as well as the magistrate of Chang'an County (one of the two counties making up the capital), but as at that time, the ranks of imperial scholars (翰林學士,
Hanlin Xueshi) was severely lacking, Xiao had him made an imperial scholar and also
Zhifang Langzhong (), also a supervisory official at the ministry of civil service affairs; Wang was also put in charge of drafting edicts. He was later made
Zhongshu Sheren (), a mid-level official at the legislative bureau. Yet later, he was made chief imperial scholar (翰林學士承旨,
Hanlin Xueshi Chengzhi) and deputy minister of census (戶部侍郎,
Hubu Shilang). While serving as chief imperial scholar, he also successively served as deputy minister of defense (兵部侍郎,
Bingbu Shilang) and then
Shangshu Zuo Cheng (), one of the secretaries general of the executive bureau (尚書省,
Shangshu Sheng). In late 880, as the major agrarian rebel
Huang Chao was approaching Chang'an, the powerful
eunuch Tian Lingzi, in order to deflect blame for the imperial forces' inability to stop Huang, blamed the leading chancellor
Lu Xi for erroneous strategies and had Lu demoted. (Lu, in response, committed suicide.) Wang and
Pei Che were made chancellors (with the designation
Tong Zhongshu Menxia Pingzhangshi ()) to replace Lu. However, on the same day, news arrived that Huang was about to attack Chang'an. Tian took Emperor Xizong and fled toward
Chengdu, and the officials scrambled to either try to follow the emperor or to hide. Wang tried to follow the emperor in flight, but in his attempt to do so fell into a bush in a valley and was injured. He was captured by Huang's soldiers, who took him back to Chang'an, where Huang had declared himself emperor of a new state of Qi. Huang tried to force Wang to accept a commission in the Qi government, but Wang pretended to have been so severely injured that he could not speak, even when swords were placed against him. Huang had Wang returned to his mansion to recuperate, under close watch, and he sent doctors to treat Wang. After about a month, though, when the guards had relaxed, Wang disguised himself as a merchant and fled to Hezhong (河中, in modern
Yuncheng, Shanxi). After Tang forces, with Li Keyong as a major contributor, defeated Huang and recaptured Chang'an early in 883, Wang, for his contribution, was made
You Pushe (), one of the heads of the executive bureau. It was said that Wang comforted the people, such that the people began to return. However, the powerful individuals inside the palace (i.e., eunuchs headed by Tian) and outside were trying to reconstruct their mansions, and they often infringed on the people's rights. When the people complained, Wang tried to exercise the laws properly against the powerful people, and thus offended them. They thus had another official, Xue Qi (), made Wang's deputy, with the intent that Xue would strip Wang's actual authority, but Wang, citing the fact that Xue's father had just died and that he should thus be observing a period of mourning, refused to let Xue take office. This further angered the powerful people, and Wang was stripped of his posts and summoned to Chengdu. He was then made a senior advisor to the
Crown Prince—an entirely honorary post as there was no crown prince at the time—and ordered to retire to Hezhong. About three months later, even that honorary post was stripped, although a similar post was conferred after Emperor Xizong returned to Chang'an in 885, and Wang was recalled to Chang'an, although he declined the post on account of illness. The chancellors, rebuking Wang for not accepting the imperial largess, had him made the prefect of Ji Prefecture (集州, in modern
Bazhong,
Sichuan) and ordered him to report immediately. Immediately after, though, Tian provoked
Wang Chongrong and Li Keyong into attacking Chang'an, and Emperor Xizong fled to Xingyuan (興元, in modern
Hanzhong,
Shaanxi). The warlord
Zhu Mei, the military governor of Jingnan Circuit (靜難, headquartered in modern
Xianyang,
Shaanxi), took over Chang'an and declared an imperial prince,
Li Yun the Prince of Xiang, emperor. Tian was removed from his post and fled to Chengdu to serve as the eunuch monitor of Xichuan Circuit (西川, headquartered in modern Chengdu), where his brother
Chen Jingxuan was military governor. After Tian's removal, Emperor Xizong sent an edict summoning Wang to serve as the minister of civil service affairs () and creating him the Marquess of Langye. Wang wanted to report to Emperor Xizong, but the roads were blocked off by Li Yun. Subsequently, Li Yun's edict arrived at Hezhong, also summoning Wang. Wang claimed to have suffered a stroke and to be unable to walk, and he refused to submit to Li Yun. After Zhu was killed by his own subordinate
Wang Xingyu later in the year, and Li Yun was then executed by Wang Chongrong when he fled to Hezhong, Emperor Xizong returned to Chang'an. He made Wang chief imperial censor (御史大夫,
Yushi Daifu), but Wang declined on account of illness. == During Emperor Zhaozong's reign ==