The grim resistance by the population against Chinese imperialist domination, which persisted century after century, time and again, broke out in the form of armed insurrection.
The most important was that of the two sisters, Trung Trac and Trung Nhi, born of a family of military chiefs in the district of Me Linh (northwest of Ha Noi). Between 40 and 43 A.D the Trung sisters launched a vast movement throughout Chiao Chih led by women in many places. Trung Trac was made "Queen" and Chinese imperialist domination was overthrown. The Han emperor, then at the peak of his power, had to send his best general, Ma Yuan "Tamer of Waters"to Chiao Chih. By the end of the year 43 A.D., the insurrection was crushed, but it left an indelible imprint on the history of the country.
However, Chinese annals kept deploring that "the people of Chiao Chih, relying on remote inaccessible areas, liked to rebel". The insurrection in the Red River valley spread to the south; military posts and the domains of imperial functionaries were attacked. Another young woman, Lady Trieu, launched a large-scale movement against foreign domination in 248 A.D. in the province of Chiu Chen (present-day Thanh Hoa Province). She said, "I'd like to ride storms, kill the sharks in the open sea, drive out the aggressors, reconquer the country, undo the tics of serfdom, and never bend my back to be the concubine of any man". Riding an elephant, she led the way to the battlefield. However, she was unable to maintain a very long resistance against the Chinese Imperial army.
Other insurrections marked the 4th and 5th centuries, including one in the year 412 when Chinese peasants who had risen in revolt and been driven out of China co-ordinated their efforts with Vietnamese patriots. The 6th century was marked by a major insurrection led by Li Bi, a notable from Long Hung in present-day Thai Binh Province, who launched his movement in 542, swept away the Chinese administration, and defeated a counter-offensive by the imperial army in 543 and an attack by the Cham in the south. In 544 Ly Bi made himself King of Van Xuan kingdom and established a national administration. However, he was defeated by the Chinese imperial army in 545-546 and died in 548, handing over command to one of his aides, Trieu Quang Phuc. The latter mustered his troops in the swampy areas of Da Trach (in present-day Hung Yen Province), carrying out guerrilla raids and making himself king after Ly Bi's death. In 550, availing himself of internal disturbances in China, he reconquered a sizable part of the nation's territory. However, the Vietnamese feudalists did not get on together and the last decades of the 6th century were marked by their rivalry, which enabled China's Sui dynasty to reconquer the country in 603.
The Sui dynasty moved the administrative capital to Tong Binh (present-day Ha Noi). In 618, the Tang dynasty took power in China; China's economy and culture saw unprecedented development as the empire experienced its greatest ever expansion. For the Tang dynasty, Chiao Chih (Viet Nam) was not only a colony for exploitation, but also a starting point for expansion into Southeast Asia. In 679, they instituted the "Protectorate of Annam (Pacified South)"; the term then came to be used for tile country itself. The Tang dynasty extended their administrative network to cover villages and mountainous regions; the annual tribute to the Court and the various taxes, cover and duties were increased. However agriculture and handicrafts in particular, continued to develop, as well as land, river and maritime communications. The three doctrines -Confucianism, Taoism, and notably Buddhism - spread nationwide, without doing away with local beliefs. The veneration of local genies, often patriots or founders of villages, remained widespread. In order to stifle deep-rooted national sentiment, the Chinese imperialists used geomancy in an attempt to drain the "veins of the dragon" running through Vietnamese soi resulting in resistance from the people. In society, more and more of those obtaining high positions in the administration through education or bribery were those who obtained important domains.
Under the Tang dynasty the country faced several invasions from the south - Champa, Java, and Malaya and from the kingdom of Nan Chiao (present-day Yunnan). In 863, Nan Chiao troops reached the capital Tong Binh and destroyed it. The Tang Court had to send General Gao Pian to fight against the Nan Chiao. Becoming governor after defeating the Nan Chiao, Gao Pian tried to suppress the nationalist movement which had continued to develop after the Tang dynasty took power.
Many insurrections took place under the Tang dynasty, including that of Ly Tu Tien and Dinh Kien in 687, of Mai Thuc Loan in 722, of Phung Hung in 766-791, and Duong Thanh in 819-820. By the end of the 9th century, internal disturbances, particularly the insurrection of Hwang Chao (874-883) in China, shook the Tang reign and China entered a long period of anarchy that started at the beginning of the 10th century. In 905, the last governor sent by the Chinese imperial court to Viet Nam died.
Taking advantage of the disturbances in China, a notable from Cuc Bo (in the present-day province of Hai Duong), Khuc Thua Du, made himself governor, and in 906 the Tang court had to recognize this fait accompli. Khuc Thua Du's son, Khuc Hao, tried to set up a national administration; in 930 the Southern Ban dynasty, which had taken power in southern China, again invaded the country. In 931, however, a patriot, Duong Dinh Nghe, took up the fight and made himself governor. After Duong Dinh Nghe died, murdered by one of his aides, the fight was led by Ngo Quyen, who in 938 clashed with a Southern Han expeditionary corps approaching by sea. The Southern Han fleet entered Vietnam via the Bach Dang estuary (mouth of the river which flows into Halong Bay) where iron-tipped stakes had been sunk into the riverbed by Ngo Quyen. At high-tide a Vietnamese flotilla attacked the enemy then, pretending to escape, lured the Southern Han boats into the estuary beyond the stakes still covered by the tide. At low-tide, the entire Vietnamese fleet counter-attacked, forcing the enemy to flee and sink, impaled on the barrage of stakes.
The Bach Dang victory in 938 put an end to the period of Chinese imperial domination. In 939 Ngo Quyen proclaimed himself king, established his capital at Co Loa (previously a capital in the 3rd century B.C.) and set up a centralized government. It was the first truly independent Vietnamese state.
Domestically, the main obstacle to the founding of a centralized power structure capable of assuming direction of the economy - management of the dyke system in particular - and of successfully resisting foreign aggression was the existence of feudal lords who each ruled an area of territory. On the death of Ngo Quyen in 944, 12 warlords divided the country among themselves and began to fight one another.
Starting from Hoa Lu in present-day Ninh Binh, Dinh Bo Linh defeated them all, one after another, and unified the country in 967. The next year he made himself king, named the country Dai Co Viet, established his capital at Hoa Lu, reorganized the army and administration, and appointed renowned Buddhist monks as advisers. The murder of Dinh Bo Linh in 979 brought a six-year-old child to the throne. Meanwhile the Sung dynasty had taken power in China where order was restored. A Sung expeditionary corps was sent to reconquer Vietnam, which was also being attacked from the south by the Cham. To deal with this danger, the Court and army appointed a talented general, Le Hoan. The latter defeated the Sung army on both land and water, thus saving the country (981). The next year, and expedition led by Le Hoan invaded the Kingdom of Champa and conquered its capital Indrapura (now in Quang Nam province), removing the threat of invasion from the south for a long time to come.