Wang Zongyi was born in 892, before the founding of the Former Shu state, as Wang Jian's second son. His mother was a Lady Zhang, who later would be given the imperial consort title of Guifei after Wang Jian founded Former Shu. As his older brother Wang Zongren, born of a Lady Ma, was disabled in his youth, Wang Zongyi was considered in effect Wang Jian's oldest son, and at some point during Wang Jian's service as a Tang Dynasty general was given the honorific title of deputy director of the archival bureau. When Wang Jian declared himself Emperor of Shu in 907, he created Wang Zongyi the Prince of Sui.
As crown prince
In 908, Wang Jian created Wang Zongyi crown prince. In 909, Wang Jian made him the titular commander of the imperial guards, and established headquarters for him, naming the headquarters Yonghe Hall. Wang Jian also selected a number of officials to serve on his staff. Wang Zongyi was said to be ugly in appearance, but talented in many things, particularly archery. However, he was also said to be arrogant and violent, paying no heed to the counsel of the officials Wang Jian put on his staff. He soon came into conflict with Wang Jian's close associate Tang Daoxi the director of palace communications, as he often made fun of Tang, leading to their mutually accusing each other of crimes. Wang Jian, not wanting them to be in constant conflict, made Tang the military governor of Shannan West Circuit in 910 to separate them. Later in 910, Wang Jian renamed him Wang Yuantan. Subsequently, when Wang Jian made two tours away from the capital Chengdu to Li Prefecture in 911 in response to attacks by Former Shu's northern neighbor Qi, he had Wang Yuantan serve as regent at Chengdu. In 912, apparently in reaction to an incident where Wang Yuantan found a bronze medallion on the outskirts of the city, which Wang Jian considered a sign of divine favor, Wang Jian renamed him Wang Yuanying. In 913, when Tang completed his term as the military governor of Shannan West and returned to Chengdu to again serve as the director of palace communications, Wang Yuanying submitted accusations against Tang and declared that Tang should not be again in charge of palace communications, Wang Jian was displeased, but subsequently reacted by making Tang an advisor to Wang Yuanying.
Uprising against Tang Daoxi and death
In fall 913, Wang Jian planned a vacation away from Chengdu for the Qixi Festival. The night before, Wang Yuanying held a feast for the imperial princes and high-level officials, but three invitees — Wang Jian's adoptive son Wang Zonghan the Prince of Ji, and the officials Pan Qiao and Mao Wenxi — did not attend. Wang Yuanying, in anger, accused Pan and Mao in absentia of alienating his brothers from him. Meanwhile, Wang Yuanying's trusted officers Xu Yao and Chang Qian were gazing at Tang. Tang, in fear, fled from the feast. The morning next day, Wang Yuanying went to see his father Wang Jian and accused Pan and Mao of alienating him from his brothers. Wang Jian, believing the accusations, ordered Pan and Mao demoted, making Pan's brother Pan Kang the new director of palace communications. However, after Wang Yuanying then left the palace, Tang arrived, and Tang made the counteraccusation that Wang Yuanying was planning to rebel, and, as part of his planning, was planning to put the princes and the officials under arrest. Wang Jian, with his suspicions aroused, cancelled the Qixi vacation plans. Further, he agreed to Tang's request to mobilize the regular troops to defend the palace. Upon hearing that the regular troops had been mobilized, Wang Yuanying mobilized his own Tianwu Army. He arrested Pan Qiao and Mao and almost battered them to death, in addition to arresting Pan Jiao the mayor of Chengdu. The next day, Xu, Chang, and Yan Lin, under Wang Yuanying's direction, attacked Tang's forces. Tang initially resisted, but tried to retreat when an arrow hit him. The crown prince's troops then routed his, killing him, and many of the troops under Tang were killed. In response, at Pan Kang's suggestion, Wang Jian summoned his adoptive sons Wang Zongkan, Wang Zonghe, and Wang Zonglu, ordering them to launch an attack against Wang Yuanying's troops. They did so, along with another adoptive son, Wang Zong'an. They killed Xu in battle. Chang and Wang Yuanying fled to Longyao Pond and hid on a boat there. The next morning, Wang Yuanying came out of hiding and requested food from the boat owner. This was reported to Wang Jian, and he dispatched Wang Zonghan to try to comfort Wang Yuanying. However, before Wang Zonghan arrived at Longyao Pond, Wang Yuanying was killed by his own guard. Wang Jian initially mourned Wang Yuanying bitterly, but later decided that without declaring Wang Yuanying a renegade, he could not comfort the people, and therefore demoted Wang Yuanying to commoner rank, although, apparently at Wang Jian's direction, Wang Zonghan had Wang Yuanying's killer executed. Many of Wang Yuanying's associates were killed or exiled.