These acts of reform paved the way for the reign of Emperor Taizong, which ultimately pushed Tang to the height of its power.
Li Bing died in 572, and Li Yuan inherited the title of Duke of Tang, a title he continued to hold after the Northern Zhou throne was seized by Emperor Wen of Sui (Yang Jian) in 581, establishing the Sui dynasty, as Emperor Wen's wife, Empress Dugu, was an aunt of his.
When Emperor Yang carried out his second campaign against Goguryeo in 613, Li Yuan was in charge of part of the logistics operation.
In fear, Li Yuan took up drinking and receiving bribes to try to show Emperor Yang that he did not have great ambitions.
In 615, Emperor Yang placed him in charge of the operations against agrarian rebels in the Hedong (河東) region (roughly modern Shanxi), but recalled him in 616.
Emperor Yang grew dissatisfied with Li Yuan and Wang Rengong (王仁恭), the governor of Mayi Commandery (馬邑, roughly modern Shuozhou, Shanxi), over their inability to stop incursions by the Eastern Turks (Tujue) and the growing strength of agrarian rebels—particularly the Turk-supported Liu Wuzhou, the Dingyang Khan, who soon rose against Wang and killed him and captured Emperor Yang's secondary palace near Taiyuan.
According to these, Li Shimin was secretly planning rebellion against Sui rule with Pei Ji, the majordomo of Emperor Yang's secondary palace, and with Liu Wenjing, the magistrate of Jinyang County (晉陽, i.e., Taiyuan), but at first did not reveal their plans to Li Yuan.
Li Yuan began to gather forces from the region, claiming that they were necessary to defend against the Turks, which drew suspicions from his deputies Wang Wei (王威) and Gao Junya (高君雅).
Li Yuan first secured his northern flank by contacting Shibi Khan, offering tribute, and received men and horses in exchange.
Let us capture Ziying at Xianyang, and let us kill Xin of Shang at Muye; would it not be a great accomplishment?Li Yuan was dismayed but, not wanting to make another enemy, wrote back humbly: Although I am ordinary and foolish, but I have had the opportunity to, by my ancestors' largess, receive the opportunity to be an imperial messenger when leaving the capital and a guard leader in the capital.
Therefore, I have organized a righteous army and sought peace with the barbarians to the north [i.e., Tujue] to try to calm the earth and to protect Sui.
I do not have the heart to hear such commands as killing Xin of Shang at Muye, nor do I dare to listen to the order of capturing Ziying at Xianyang.
Meanwhile, however, when Li Yuan arrived near Hedong, his army was bogged down by the weather, and with food running out, there were rumors that Eastern Tujue and Liu Wuzhou would attack Taiyuan.
After defeating Sui forces at Huoyi (霍邑, also in modern Yuncheng), he decided to leave a small contingent to watch over Hedong while advancing across the Yellow River into Guanzhong (i.e., the Chang'an region).
In spring 618, Emperor Yang was killed at Jiangdu (江都, in modern Yangzhou, Jiangsu) in a coup led by the general Yuwen Huaji.
When the news reached Chang'an, Li Yuan had Yang You yield the throne to him, becoming Emperor Gaozu of the Tang dynasty.
Meanwhile, Li Mi, having been defeated earlier in the year in a surprise attack (at the Battle of Yanshi) by the Sui general Wang Shichong, fled to Tang territory and submitted to Gaozu.
Around New Year 619, Li Mi requested Emperor Gaozu's permission to head east to persuade some of his former subordinates to submit to Tang, but once he left Chang'an, planned to restore his independence.
In spring 619, Wang Shichong at Luoyang had Yang Tong yield the throne to him, ending the Sui dynasty and establishing a new state of Zheng.
Also around the same time, the rebel leader Du Fuwei, who controlled the modern southern Anhui, submitted to Tang, and Gaozu also bestowed the imperial surname of Li on him, creating him the Prince of Wu.
Similarly, Luo Yi, who controlled the modern Beijing region, submitted, was bestowed the imperial surname of Li, and was created the Prince of Yan.
Li Zitong, in turn, defeated and took over the territory of Shen Faxing the Prince of Liang, roughly modern Zhejiang.
In summer 621, the Tang and Xia forces engaged at Hulao, and Li Shimin defeated Dou, capturing him.
Xia territory was also seized by Tang, but after Emperor Gaozu executed Dou, Dou's general Liu Heita rose against the Tang and seized most of the former Xia territory, while Xu Yuanlang, a rebel leader who had previously submitted to Zheng, also rose in revolt, occupying the modern Shandong region.
Meanwhile, while not as noted as Emperor Gao of Han's killing of Han Xin and Peng Yue, historians have nevertheless noted that some contributors to Emperor Gaozu's establishment of Tang were wrongly killed by him or killed based on fairly little evidence of wrongdoing: In spring 622, Li Shimin defeated Liu Heita, forcing him to flee to the Eastern Turks, but Liu Heita soon returned with Turkic reinforcements and killed Emperor Gaozu's nephew Li Daoxuan (李道玄) the Prince of Huaiyang in battle, again seizing former Xia territory, although by this point Li Shimin and Li Yuanji had also defeated Xu Yuanlang and reduced his territory to a few cities.
Liu fled north toward the Eastern Turks, but was ambushed and captured by his own official Zhuge Dewei (諸葛德威), who delivered him to Li Jiancheng.
Meanwhile, Lin Shihong the Emperor of Chu, who had one point controlled modern Jiangxi and Guangdong, had died, and his followers scattered.
China was by this point completely unified by Tang except for the domain of Liang Shidu the Emperor of Liang, who controlled modern northern Shaanxi and western Inner Mongolia, although, with Li Fuwei at Chang'an, Fu Gongshi rebelled in 623 and declared himself the Emperor of Song.
Li Jiancheng briefly flirted the idea of occupying Chang'an and not accepting the order, but eventually reported to Renzhi Palace to request forgiveness.
In 630, when Emperor Gaozu, who had been submitting tribute to the Eastern Turks throughout his reign, heard that Emperor Taizong had sent the general Li Jing to defeat and capture the Turkic khagan Jiali Khan (Ashina Duobi), commented, "Gaozu of Han was trapped [at Baideng (白登, in modern Datong, Shanxi) in 200 BCE by Xiongnu forces] and could not avenge himself.