The Tay Son Rebellion (1771-1802), which ended the Le and Trinh dynasties, was led by three brothers from the village of Tay Son in Binh Dinh Province. The brothers, who were of the Ho clan (to which Ho Quy Ly had belonged), adopted the name Nguyen. The eldest brother, Nguyen Nhac, began an attack on the ruling Nguyen family by capturing Quang Nam and Binh Dinh provinces in 1772. The chief principle and main slogan of the Tay Son was "seize the property of the rich and distribute it to the poor." In each village the Tay Son controlled, oppressive landlords and scholar-officials were punished and their property redistributed. The Tay Son also abolished taxes, burned the tax and land registers, freed prisoners from local jails, and distributed the food from storehouses to the hungry. As the rebellion gathered momentum, it gained the support of army deserters, merchants, scholars, local officials, and bonzes.
In 1773 Nguyen Nhac seized Qui Nhon, which became the Tay Son capital. By 1778 the Tay Son had effective control over the southern part of the country, including Gia Dinh (later Saigon). The ruling Nguyen family were all killed by the Tay Son rebels, with the exception of Nguyen Anh, the sixteen-year-old nephew of the last Nguyen lord, who escaped to the Mekong Delta. There he was able to gather a body of supporters and retake Gia Dinh. The city changed hands several times until 1783, when the Tay Son brothers destroyed Nguyen Anh's fleet and drove him to take refuge on Phu Quoc Island. Soon thereafter, he met with French missionary bishop Pigneau de Behaine and asked him to be his emissary in obtaining French support to defeat the Tay Son. Pigneau de Behaine took Nguyen Anh's five-year-old son, Prince Canh, and departed for Pondichery in French India to plead for support for the restoration of the Nguyen. Finding none there, he went to Paris in 1786 to lobby on Nguyen Anh's behalf. Louis XVI ostensibly agreed to provide four ships, 1,650 men, and supplies in exchange for Nguyen Anh's promise to cede to France the port of Tourane (Da Nang) and the island of Poulo Condore. However, the local French authorities in India, under secret orders from the king, refused to supply the promised ships and men. Determined to see French military intervention in Vietnam, Pigneau de Behaine himself raised funds for two ships and supplies from among the French merchant community in India, hired deserters from the French navy to man them, and sailed back to Vietnam in 1789.
In the meantime, by 1786 the Tay Son had overcome the crumbling Trinh dynasty and seized all of the north, thus uniting the country for the first time in 200 years. The Tay Son made good their promise to restore the Le dynasty, at least for ceremonial purposes. The three Nguyen brothers installed themselves as kings of the north, central, and southern sections of the country respectively, while continuing to acknowledge the Le emperor in Thang Long. In 1788, however, the reigning Le emperor fled north to seek Chinese assistance in defeating the Tay Son. Eager to comply, a Chinese army of the Qing dynasty (1644-1911) invaded Vietnam, seized Thang Long, and invested the Le ruler as "King of Annam." That same year, the second eldest Tay Son brother, Nguyen Hue, proclaimed himself Emperor Quang Trung. Marching north with 100,000 men and 100 elephants, Quang Trung attacked Thang Long at night and routed the Chinese army of 200,000, which retreated in disarray. Immediately following his victory, the Tay Son leader sought to reestablish friendly relations with China, requesting recognition of his rule and sending the usual tributary mission.
Quang Trung stimulated Vietnam's war-ravaged economy by encouraging trade and crafts, ordering the recultivation of fallow lands, reducing or abolishing taxes on local products, and resettling landless peasants on communal lands in their own villages. Quang Trung also established a new capital at Phu Xuan (near modern Hue), a more central location from which to administer the country. He reorganized the government along military lines, giving key posts to generals, with the result that military officials for the first time outranked civilian officials. Vietnamese was substituted for Chinese as the official national language, and candidates for the bureaucracy were required to submit prose and verse compositions in chu nom rather than in classical Chinese.
Quang Trung died in 1792, without leaving a successor strong enough to assume leadership of the country, and the usual factionalism ensued. By this time, Nguyen Anh and his supporters had won back much of the south from Nguyen Lu, the youngest and least capable of the Tay Son brothers. When Pigneau de Behaine returned to Vietnam in 1789, Nguyen Anh was in control of Gia Dinh. In the succeeding years, the bishop brought Nguyen Anh a steady flow of ships, arms, and European advisers, who supervised the building of forts, shipyards, cannon foundries and bomb factories, and instructed the Vietnamese in the manufacture and use of modern armaments. Nguyen's cause was also greatly aided by divisions within the Tay Son leadership, following the death of Quang Trung, and the inability of the new leaders to deal with the problems of famine and natural disasters that wracked the war-torn country. After a steady assault on the north, Nguyen Anh's forces took Phu Xuan in June 1801 and Thang Long a year later.