Li Yuan made both Li Jiancheng and Li Shimin key generals, and in nine days, they captured Xihe Commandery , impressing their father. Subsequently, Li Yuan divided his forces into six armies, having Li Jiancheng and Li Shimin command three each. He also created Li Jiancheng the Duke of Longxi and Li Shimin the Duke of Dunhuang. Subsequently, Li Yuan advanced toward Chang'an, but when he got near to Hedong, his army could not advance due to torrential rains. With rumors running rampant that Liu Wuzhou and Eastern Tujue were about to attack Taiyuan, Li Yuan began ordering a retreat back to Taiyuan; it was only at Li Jiancheng's and Li Shimin's urging that Li Yuan changed his mind and stayed, and Li Jiancheng and Li Shimin then captured the fortress of Huoyi , eventually convincing Li Yuan to bypass Hedong and directly advance toward Chang'an. After he crossed the Yellow River into Guanzhong , he sent Li Jiancheng with Liu Wenjing east to guard Tong Pass and Yongfeng Storage and to stop any potential Sui reinforcements from the eastern capital Luoyang. Once Li Yuan himself approached Chang'an, he summoned both Li Jiancheng and Li Shimin to Chang'an to join him in sieging Chang'an. In winter 617, Li Yuan captured Chang'an and declared Yang You emperor . He had himself created the Prince of Tang, become the regent over Emperor Gong.
Rivalry with Li Shimin
Meanwhile, an intense rivalry had developed between Li Jiancheng and Li Shimin, who carried the title of Prince of Qin, as while Li Jiancheng had some contributions toward Tang's reunification of China, a number of the more major contenders, including Xue Rengao the Emperor of Qin, Wang Shichong the Emperor of Zheng, and Dou Jiande the Prince of Xia, were all defeated and/or captured by Li Shimin, causing him to possess the greater reputation among the army. Li Yuanji, who was also often relied on by Emperor Gaozu as a general and had been created the Prince of Qi, supported Li Jiancheng in this rivalry, and often pushed Li Jiancheng toward a more hardline position against Li Shimin, wanting to be crown prince when Li Jiancheng would become emperor. Li Jiancheng and Li Yuanji had better relations with Emperor Gaozu's favored young concubines than Li Shimin did , and those concubines helped rehabilitate Li Jiancheng's standing before Emperor Gaozu, causing him to no longer consider making Li Shimin crown prince instead, as he considered at one point.
By winter 622, Liu Heita the Prince of Handong, previously a Xia general who rose against Tang after Emperor Gaozu had executed Dou Jiande, posed the only remaining major threat against Tang rule even though he had been defeated by Li Shimin earlier in the year. At the suggestion of his staff members Wang Gui and Wei Zheng, who argued that Li Jiancheng needed some victories himself to establish his reputation, Li Jiancheng volunteered to command the army against Liu Heita. Emperor Gaozu thus sent Li Jiancheng, assisted by Li Yuanji. Around the new year 623, with Liu's forced bogged down while attacking Tang's Wei Prefecture , Li Jiancheng and Li Yuanji engaged him at Guantao , crushing him. Liu fled north toward Eastern Tujue, but was ambushed and captured by his own official Zhuge Dewei , who delivered him to Li Jiancheng. Li Jiancheng executed Liu. China was by this point almost completely unified by Tang.
In 624, Li Jiancheng requisitioned a number of soldiers from the general the Prince of Yan, to supplement his guard corps, against Emperor Gaozu's regulations. When this was revealed to Emperor Gaozu, Emperor Gaozu rebuked Li Jiancheng and exiled his guard commander Keda Zhi . When, subsequently, Li Jiancheng nevertheless requested the commandant at Qing Prefecture , Yang Wen'gan , to conscript troops, presumably to guard against Li Shimin, the officers Erzhu Huan and Qiao Gongshan informed Emperor Gaozu that Li Jiancheng was encouraging Yang to start a rebellion so that they could seize power together. Emperor Gaozu, then at Renzhi Palace , was incensed, and summoned Li Jiancheng, then at Chang'an, to Renzhi Palace. Li Jiancheng briefly flirted the idea of occupying Chang'an and not accepting the order, but eventually reported to Renzhi Palace to request forgiveness. Emperor Gaozu put him under arrest. When Yang heard this, Yang rebelled, and Emperor Gaozu, after promising Li Shimin that he would be made crown prince, sent Li Shimin to attack Yang. Once Li Shimin left, however, Li Yuanji, Emperor Gaozu's concubines, and the chancellor Feng Deyi, all spoke on Li Jiancheng's behalf, and Emperor Gaozu changed his mind, released Li Jiancheng, and allowed him to return to Chang'an and remain as crown prince. Instead, Emperor Gaozu only blamed the discord between his sons on Li Jiancheng's staff members Wang Gui and Wei Ting , and Li Shimin's staff member Du Yan, exiling them. Yang was subsequently assassinated by his own subordinates.
In summer 626, Eastern Tujue was making another attack, and under Li Jiancheng's suggestion, Emperor Gaozu, instead of sending Li Shimin to resist Eastern Tujue as he first was inclined, decided to send Li Yuanji instead. Li Yuanji was given command of much of the army previously under Li Shimin's control, further troubling Li Shimin, who believed that with the army in Li Yuanji's hands, he would be unable to resist an attack. Li Shimin had Yuchi summon Fang and Du back to his mansion secretly, and then on one night submitted an accusation to Emperor Gaozu that Li Jiancheng and Li Yuanji were committing adultery with Emperor Gaozu's concubines. Emperor Gaozu, in response, issued summonses to Li Jiancheng and Li Yuanji for the next morning, convening the senior officials Pei Ji, Xiao Yu, and Chen Shuda to examine Li Shimin's accusations. As Li Jiancheng and Li Yuanji approached the central gate leading to Emperor Gaozu's palace, Xuanwu Gate , Li Shimin carried out the ambush he had set. He personally fired an arrow that killed Li Jiancheng. Subsequently, Yuchi killed Li Yuanji. Li Shimin's forces entered the palace and, under the intimidation of Li Shimin's forces, Emperor Gaozu agreed to create Li Shimin crown prince, and two months later passed the throne to him . Li Jiancheng's five sons were all executed as well.