The Sui Dynasty (590-618) only had two emperors. At the end of the Sui, peasant uprisings rapidly swept throughout the country due to heavy taxation and extravagance of the emperor, which made the common people suffer a lot. Furthermore, the emperor tried three times to invade the northern part of Korea but never succeeded, rapidly worsening the situation.
Li Yuan was originally an aristocrat of the Sui Dynasty. In the year 617 he was dispatched to Tai Yuan by Sui Yangdi (the Emperor Yang of the Sui Dynasty), to battle the rebellion by the peasants there. Li Shimin, the second and also the most capable among all of Li Yuan's sons, had his own plans as he was sure that Sui would not last long. Li Shimin's friend Liu Wenjing suggested that he raise troops and rebel against the Sui Dynasty. Li Shimin thought that there was something in what he suggested and persuaded his father to do so.
Li Shimin, who, at the age of sixteen, already showed his outstanding military ability, suggested his father borrow military power from a formal enemy country of the Sui dynasty -- the Hun. Li Yuan consented to his suggestion and asked Liu Wenjing to help him to recruit soldiers and increase military power.
Before long, Li Yuan left Jin Yang and headed for Chang'an together with 30,000 soldiers. On the way there, they gave rice to peasants and won their heart, which was the routing practice by the rebellious armies. After they conquered the city of Huo Yi, they crossed the Yellow River and summoned up about 200,000 people with the help from the peasant rebels from Guan Zhong. They were all ready to attack Chang'an, the capital city.
After the army taking Chang'an in a flash, to gain the hearts of the public, Li Yuan abolished all the bans announced by the Sui Dynasty, and made Yang You, son of Sui Yangdi, nothing but a temporary puppet emperor. When Sui Yangdi was assassinated by an aide in 618, Li Yuan deposed the puppet prince and declared himself emperor, and changed the name of the empire to the Tang Dynasty (618-907). The years of his reign were spent consolidating the kingdom, and he was again ably assisted by his second son, Li Shimin who continued to command the rebel armies and conquered all other rebellions.
On taking the title and name Emperor Gaozu, Li Yuan who had twenty-two sons in total, decreed that his eldest son, Li Jiancheng, should be the Crown Prince. Li Shimin, the second son, was granted the title Prince of Qin. A third son had died long before, so the fourth son, Li Yuanji was created Prince of Qi.
Of these three sons, Li Shimin was the most ambitious and intelligent. It was he who had made the greatest contributions to the campaign to secure the empire for his father. This fact troubled the Crown Prince for he saw Li Shimin as a threat to his own position. Conspiring with his younger brother, Prince Qi, he tried to get rid of Li Shimin.
Unhappy with his father's incompetence and tired of the constant threats against him by his brothers, Li Shimin launched a palace coup at the Xuanwu Gate in 626. Both the Crown Prince and Prince Qi were killed. This was recorded as The Xuanwu Gate Coup. As a result, Li Yuan was then compelled to abdicate in favor of Li Shimin, and the latter ascended the throne as Emperor Taizong.
In the early Tang, the country was strong and prosperous and the government honest and clean. Taxes and corvee were reduced, and the feudal economy and culture flourished.
Although he founded an incredibly long-lived dynasty, Li Yuan himself only reigned for a few years before he was ousted by his son, Li Shi-min. Li Yuan retired in 626 and Li Shimin, who also known as Tang Taizong, continued his father's success. Tang Gaozu died in 635 and buried in Xian Mausoleum.