Wang Gui (571–639), courtesy name Shujie, posthumously known as Duke Yi of Yongning, was a Chinese official who served as a chancellor during the reign of Emperor Taizong (Li Shimin) in the Tang dynasty. He had previously served Li Shimin's elder brother, Li Jiancheng, with whom Li Shimin was locked in an intense rivalry during the reign of their father, Emperor Gaozu, but after Li Shimin killed Li Jiancheng and then took the throne, he knew that Wang was faithful to Li Jiancheng and was capable, and therefore retained him, eventually making him chancellor.  Wang was known for his honest and blunt criticism of the emperor, and for that was honored by Taizong, who appreciated such criticism.

Background 
Wang Gui was born in 571, during the reign of Northern Qi's emperor Gao Wei.  His grandfather Wang Sengbian had been a major general and later regent of Liang Dynasty, who, at one point, in order to make peace with Northern Qi, sent Wang Gui's father Wang Yi (王顗) and grandmother to Northern Qi as hostages.  After Wang Sengbian was killed in a coup by the general Chen Baxian (who later founded Chen Dynasty) in 555, Wang Yi remained in Northern Qi and served as a commandery governor.  In 573, after the former Liang general Wang Lin, with whom Wang Yi shared the desire of destroying Chen and reestablishing Liang, was killed by the Chen general Wu Mingche, Wang Yi, in great distress in mourning Wang Lin, died.  Wang Gui, having lost his father early in his life, was said to be elegant in his behavior, having few desires and comfortable in his poverty, and not making friends easily with just anyone.  His uncle Wang Po (王頗) was a highly regarded scholar at that time and was said to be a good judge of character, and Wang Po once commented, "Our clan's hopes all rest on this child."

During Sui Dynasty 
Near the end of the reign of Emperor Wen of Sui, Wang Gui served as a low-level imperial official in charge of ceremonies.  After Emperor Wen died in 604, his crown prince Yang Guang took the throne as Emperor Yang.  Another son of Emperor Wen, Yang Liang the Prince of Han, on whose staff another uncle of Wang Gui's, Wang Kui (王頍), served, rose in rebellion against Emperor Yang, and after he was defeated, Wang Kui committed suicide, and Wang Po was executed.  Based on the laws of the time, Wang Gui was to be executed as well, but he fled into the Qinling Mountains and remained in hiding there for more than a decade.

In 617, the general Li Yuan rose against Emperor Yang, and later that year captured the capital Chang'an, declaring Emperor Yang's grandson Yang You the Prince of Dai emperor (as Emperor Gong) but retaining power himself as regent.  Li Yuan's staff member Li Gang (李綱) recommended Wang Gui, as he knew Wang Gui's capabilities.  Li Yuan made Wang Gui a military advisor to his heir apparent Li Jiancheng.

During Emperor Gaozu's reign 
In 618, after news arrived at Chang'an that Emperor Yang had been killed in a coup at Jiangdu (江都, in modern Yangzhou, Jiangsu) led by the general Yuwen Huaji, Li Yuan had Yang You yield the throne to him, establishing Tang Dynasty as its Emperor Gaozu.  He created Li Jiancheng crown prince, and Wang Gui continued to serve on Li Jiancheng's staff as a trusted advisor.  In 622, with Tang having mostly reunited the former Sui territory under its rule due to the contributions of Li Jiancheng's younger brother Li Shimin the Prince of Qin, Li Shimin's fame and power thus threatened Li Jiancheng's position.  Wang and Wei Zheng, another advisor to Li Jiancheng, suggested that he should also try to establish some military achievement of his own and also recruit capable people to serve on staff during the campaign.  Li Jiancheng agreed, and volunteered to attack one of the remaining threats against Tang rule, Liu Heita the Prince of Handong.  Li Jiancheng subsequently defeated Liu, who was then betrayed by his own subordinate Zhuge Dewei (諸葛德威) in 623 and delivered to Li Jiancheng, who executed Liu.  Subsequently, in 624, when Li Jiancheng was suspected of having recruited his personal guards against regulations and having encouraged his guard commander Yang Wen'gan (楊文幹) into rebelling, Emperor Gaozu briefly considered deposing Li Jiancheng and replacing him with Li Shimin, but changed his mind after intercession by the chancellor Feng Deyi, another son Li Yuanji the Prince of Qi, and his concubines (who were on much better relations with Li Jiancheng than with Li Shimin).  However, he blamed Li Jiancheng's and Li Shimin's staff members for encouraging their rivalry, and he exiled Wang Gui, Wei Ting (韋挺, another of Li Jiancheng's advisors), and Du Yan (an advisor to Li Shimin) to Xi Prefecture (巂州, roughly modern Liangshan Yi Autonomous Prefecture, Sichuan), blaming them for the discord between his sons.

In 626, Li Shimin ambushed Li Jiancheng and Li Yuanji at Xuanwu Gate and killed them, and then effectively forced Emperor Gaozu to create him crown prince.  Rather than slaughtering Li Jiancheng's and Li Yuanji's staff members, as some of his supporters had suggested, he retained many of them for his administration, including Wei Zheng.  He also recalled Wang Gui and Wei Ting from exile, making them advisors.  When many of Li Jiancheng's and Li Yuanji's supporters nevertheless fled in fears of reprisals and were captured by those who believed that they could receive awards, Wang informed this to Li Shimin, who then issued an order not to carry out any reprisals against the followers of Li Jiancheng, Li Yuanji, or their cousin Li Yuan (李瑗, note different tone and character from Emperor Gaozu's name) the Prince of Lujiang (who had supported Li Jiancheng and considered rebelling in light of Li Jiancheng's death).  Soon, Emperor Gaozu yielded the throne to Li Shimin (as Emperor Taizong).  Wang continued to serve in Emperor Taizong's administration.

During Emperor Taizong's reign 
Later in 626, Emperor Taizong had Li Jiancheng and Li Yuanji reburied with honors due imperial princes.  Wang Gui and Wei Zheng requested permission to accompany Li Jiancheng's funeral procession, and Emperor Taizong approved—and further expanded the approval to an order that all of Li Jiancheng's and Li Yuanji's staff members participate in the funeral processions.

In 627, on an occasion, Emperor Taizong stated to his high-level officials:

When a good emperor encountered evil subordinates, the empire will not prosper.  When an evil emperor encountered good subordinates, the empire will also not prosper.  But if an emperor and his subordinates were like fish and water, the empire will have peace.  Emperor Gaozu of Han was but a farmer, but he conquered the empire carrying just a short sword.  His foundation was strong, and his descendants ruled for generations, because he had good subordinates.  Even though I am not an intelligent ruler, it is fortunate that I have you, Dukes, to save me occasion after occasion.  I hope that you will give me good strategies to allow the empire to remain peaceful.

Wang responded:

I heard that if a tree follows a rope it will be straight, and if an empress followed suggestions she would be holy.  Therefore, the ancient holy rulers always had seven advisors who were willing to speak honestly and willing to die if their suggestions were not followed.  Your Imperial Majesty is willing to receive our weed-like suggestions, and I happen to be serving here in an administration that has no taboos.  I am willing to offer my wild words.

Emperor Taizong approved of Wang's response and ordered that whenever high-level officials would meet with him to discuss important matters of state, officials whose responsibilities were criticism should follow them in.  He treated Wang with kindness, creating him the Baron of Yongning and made him the deputy head of the examination bureau of government (門下省, Menxia Sheng) as well as an advisor for his son and crown prince Li Chengqian.  Later that year, the head of the examination bureau, Gao Shilian, was demoted after he withheld a petition from Wang, and in 628, Emperor Taizong made Wang the acting head of the examination bureau instead—a post considered as one for a chancellor.

On an occasion in 628, Wang was attending a feast held by Emperor Taizong, when a beautiful concubine of Emperor Taizong's, who was originally a concubine of Li Yuan the Prince of Lujiang and who was taken into Emperor Taizong's palace after Li Yuan was executed, was attending to Emperor Taizong.  Emperor Taizong stated, "The Prince of Lujiang was despicable.  He killed her husband and seized her.  How could he survive long after this barbarous act!"  Wang instead responded, "Does Your Imperial Majesty believe that the Prince of Lujiang was correct in seizing this woman?"  Emperor Taizong responded, "Why do you ask me whether it is correct to kill a woman's husband and seize her?"  Wang responded, "I had once read from the writings of Guan Zhong, which stated, 'When Duke Huan of Qi visited the land of Guo [formerly an independent state], he asked the seniors of Guo, "Why was Guo destroyed?"  The seniors stated, "The lord of Guo knew right from wrong."  Duke Huan responded, "If you are correct, then he was an intelligent ruler.  Why was he destroyed?"  The seniors responded, "The lord of Guo knew what was right but could not do it.  He also knew what was wrong but could not stop doing it.  That was why he was destroyed."'  Now, this woman is still by your side.  I believe it is that Your Imperial Majesty in fact believes that this is right.  If you believe that this is wrong, you are the one who knows what is wrong and could not stop doing it."  Although Emperor Taizong could not send away the woman, he was nevertheless humbled by Wang's words and respected him for his words.  On another occasion, there was an incident where Emperor Taizong had the official Zu Xiaosun (祖孝孫) teach his ladies in waiting music, and when the ladies in waiting could not learn it well, rebuked Zu.  Wang and Wen Yanbo spoke against the rebuke, stating that it was not appropriate for Emperor Taizong to have had an important official become a music teacher for ladies in waiting in the first place.  Emperor Taizong became angry and rebuked Wen and Wang.  Wen bowed and begged for forgiveness, but Wang refused to do so, stating to Emperor Taizong that the rebuke to him and Wen was not warranted as they were reporting what was true.  Emperor Taizong was surprised, but the next day indicated to the high-level officials that he was rash and improper in rebuking Wang and Wen.

In 630, Emperor Taizong officially made Wang the head of the examination bureau.  On an occasion that year, at a feast Emperor Taizong held for the chancellors, he stated to Wang, "You are known for your good judgment, and you are also a good speaker.  Please, starting with Fang Xuanling, discuss what these officials' strengths are."  Wang responded:

As far as being careful and being dedicated to the state, and doing everything that he felt was right, I am not as capable as Fang Xuanling.  As far as being capable in both civilian and military matters -- being a great general while not at the capital and being a chancellor while in the capital -- I am not as capable as Li Jing.  As far as writing imperial edicts and reporting on important matters, doing so in detail and clearly with fair analysis, I am not as capable as Wen Yanbo.  As far as handling complicated issues and emergency matters well, I am not as capable as Dai Zhou.  As far as always wishing that the emperor can be compared to Emperor Yao and Emperor Shun and viewing correcting the emperor as his responsibility, I am not as capable as Wei Zheng.  But as far as eliminating those lacking virtues and abilities, promoting those who are capable and virtuous, hating evil, and liking righteousness, this is my strength compared to the gentlemen here.

Emperor Taizong agreed strongly, and those present also agreed this as fair analysis.  Wang further advocated ruling the state by Confucian principles, a position that Emperor Taizong agreed with.  Soon, Emperor Taizong upgraded his title to duke.

In 633, Wang was accused of leaking state secrets, and he was demoted to the post of prefect of Tong Prefecture (同州, roughly modern Weinan, Shaanxi).  In 634, Emperor Taizong recalled him to be the minister of ceremonies.  In 637, he finished compiling a work on proper ceremonies, and for this contribution Emperor Taizong awarded him with silk and created one of his sons a baron.  That year, he was also made the teacher of Emperor Taizong's favorite son Li Tai the Prince of Wei.  By Emperor Taizong's orders, Li Tai treated Wang with honors due a teacher, and Wang also accordingly treated Li Tai as a student.  Also around the time, Emperor Taizong's daughter Princess Nanping was due to marry Wang's son Wang Jingzhi (王敬直).  At those times, the customs were that when a princess married into an official's household, her parents-in-law were to bow to her.  Wang believed this to be improper—that princesses needed to be in their proper roles as daughters-in-law, and therefore he instead accepted bows from Princess Nanping.  After this, it became customary for princesses to bow to their parents-in-law.  Similarly, in 638, Wang submitted a petition pointing out that it was improper to have the high-level officials bow to imperial princes and that it should be the reverse—a suggestion that Emperor Taizong was initially offended by and resisted, but after Wei Zheng pointed out that this would reduce speculations that imperial princes would take the place of the crown prince, Emperor Taizong approved Wang's suggestion.

It was said that when Wang was young and received help from others, he would not thank them.  However, after he became an honored official, he sought those who had helped him in the past and repaid them greatly—and if they had died already, repaid their families.  He was kind in supporting his widowed sister-in-law and his nephews, and often helped clan members who were less fortunate.  However, he was also criticized for not building an ancestral temple, instead only sacrificing to the ancestors privately at home.  At one point, he was thus accused by other officials of being not filially pious.  Emperor Taizong did not punish him, but had the ministry of constructions construct a temple for Wang to shame him.

In 639, Wang grew ill.  Emperor Taizong ordered Princess Nanping to attend to him, and also sent Tang Jian the minister of census to look after Wang's meals and medicines.  Wang soon died, and Emperor Taizong mourned him.  Emperor Taizong also sent Li Tai and the officials to attend Wang's wake.

References 
 Old Book of Tang, vol. 70.
 New Book of Tang, vol. 98.
 Zizhi Tongjian, vols. 190, 191, 192, 193, 194, 195.

571 births
639 deaths
Sui dynasty government officials
Chancellors under Emperor Taizong of Tang