In 602 general Liu Fang of the Sui dynasty led 270,000 soldiers to invade Vietnamese kingdom of Vạn Xuân. The King of Vạn Xuân Lý Phật Tử in capital Long Biên had to surrender to Liu Fang and he was captured to Chang'an. Sui dynasty annexed Vạn Xuân as a province and renamed it Giao Châu, "Giao province". Liu Fang was nominated as the viceroy of Giao Châu. He died after conquering the Kingdom of Champa and Qiū He replaced him to rule the land. However, in 618, Emperor Gaozu overthrew the Sui dynasty and established the Tang dynasty, and Qiū He submitted to the new Emperor, incorporating Vietnam into the Tang dynasty.
List of governors
Viceroy of Jiaozhou
Liu Fang
Qiu He under Sui under Tang
Li Daliang
Li Shou
Li Daoxing
Li Dao’an
Li Jian
Duhu of Annam
Liu Yanyou 681-687
Guo Chuke
Abe no Nakamaro 761-767
Wu Chongfu 777-782
Li Mengqiu 782
Zhang Ying 788
Pang Fu 789
Gao Zhengping 790-791
Zhao Chang 791-802
Pei 802-803
Zhao Chang 804-806
Ma Zong 806-810
Zhang Mian 813
Pei Xingli 813-817
Li Xianggu 817-819 - killed by Yang Qing
Yang Qing 819-820 - rebelled and killed by Gui Zhongwu
The Tang Dynasty quelled three revolts in northern Vietnam between 722 and 728, using an army of natives pressed into service under the leadership of Chinese generals. The Chinese generals were brutal in suppressing the insurrection: one ordered the decapitated bodies of 80,000 scalped and flayed rebels stacked into a pyramid. Although Chinese governors were sent to rule over Annam, a series of local emperors were unofficial rulers under Chinese control:
Mai Thiếu Đế 722–723? – referred to as the Juvenile Emperor, he was the son of Mai Hắc Đế and ruled only briefly following his father's death and overrun by the 100,000 men strong Tang army
Phùng An 799–802 – son of Phùng Hưng and was defeated by the Tang army
Vương Quý Nguyên led a rebellion in 803
Dương Thanh led a rebellion in 819–820
Restored autonomy
Nanzhao invaded the area of Jiaozhi modern day Vietnam multiple times in the 9th century until the Tang sent Gao Pian to defeat Nanzhao and restoring Tang rule to Jiaozhou. Taking advantage of disturbances at the end of Tang Dynasty, a native noble from Cuc Bo, Khúc Thừa Dụ, made himself Jiedushi of Jinghai in 905, and in 906 the Tang court had to recognize this a fait accompli. Khúc Thừa Dụ was admired by the people, he later worked with the Tang to establish himself as the first local self-appointed governor who ended the practice of governors sent by the Imperial court from other regions. Khuc Thua Du's son, Khúc Hạo, tried to set up a national administration. After the Tang dynasty was ousted by the Later Liang in northern China, China split in different Kingdoms during the Five Dynasties and Ten Kingdoms period. The Emperors of Later Liang in Northern Central China and the Southern Han in Southern China both claimed to be the sole legitimate Emperors of China. The Jiedushi Khúc Thừa Mỹ chose to recognize the Later Liang in Central China as the legitimate ruler and acknowledged themselves as part of the Later Liang and resisted and fought against the Southern Han. Unlike most of Tang provinces during the Five Dynasties era, Tĩnh Hải Quân did not declared independence. In 930 the Southern Han dynasty had taken power in southern China, again invaded the country and defeated Khúc Thừa Mỹ. In 931, another local, Dương Đình Nghệ took up the fight and made himself governor. In 931, Dương Đình Nghệ was murdered by his aide Kiều Công Tiễn. Ngô Quyền, a general under Nghệ, revolted against Tiễn and took control of the military. In 938, a Southern Han fleet entered Vietnam by sea via the Bạch Đằng estuary. Ngô Quyền ordered iron-tipped stakes to be planted into the riverbed. At high-tide, a Vietnamese flotilla attacked the enemy then, pretending to escape, lured the Han ships into the water where the stakes, still covered by the tide, are beneath. At low-tide, the Vietnamese fleet counter-attacked, forcing the enemy to flee and impaled on the barrage of stakes. The Bạch Đằng victory in 938 put an end to the period of Chinese imperial domination. In 939 Ngô Quyền proclaimed himself not Governor but King, establishing the Ngô Dynasty. He put his capital at Cổ Loa, the old capital of Âu Lạc in the 3rd century BC and set up a centralized government. After Ngô Quyền's death, Vietnam became embroiled in the Anarchy of the 12 Warlords. In 968, Đinh Bộ Lĩnh unified the country and declared himself as Emperor of Đại Cồ Việt.