The Tây Sơn wars or Tây Sơn rebellion, often known as the Vietnamese civil war of 1771–1802, were a series of military conflicts that followed the Vietnamese peasant uprising at Tây Sơn (in Central Vietnam) that were led by three brothers: Nguyễn Nhạc, Nguyễn Huệ, and Nguyễn Lữ. These revolutionary forces grew and later overthrew the ruling Vietnamese elite families and the ruling Lê dynasty. The Tây Sơn leaders installed themselves as rulers of Vietnam that held power until they were overthrown by Nguyễn Phúc Ánh, a descendant of the Nguyễn lord who was previously overthrown by the Tây Sơn. The war ended in 1802 when Nguyễn Phúc Ánh (now called Emperor Gia Long) defeated the Tây Sơn and reunited Đại Việt, then renamed the country to Vietnam.

Background Breakdown of royal rule in the 16th century The origin of the conflicts was back to the 15th century, when the Vietnamese monarch Lê Thánh Tông (r. 1460 – 1497) started adopting Ming-inspired Confucian reforms over the country. Under his rule, the country became a prosperous regional superpower and its population expanded from 1.8 million in 1417 to 4.5 million people at the end of his reign. The Lê royal family indefinitely exchanging Confucian niceties over the question of responsibility. He brought Dong-Kinh scholars and Thanh-Nghe warriors into his government. Lê Thánh Tông transformed Đại Việt into a centralized bureaucratic state with a strongly Confucian character and established the Nam-giao (Ch. Nan-chiao), a sacrifice to Heaven, as the new central state ritual. To staff the new bureaucracy, the Le dynasty king, referred to as an emperor in the Vietnamese records, for the first time consistently utilized the triennial examination system of the Ming dynasty to recruit scholars for appointment in the civil service. This administrative system constituted the Hong Duc model, named after the second of Le Thanh Tong's two reign periods. Meanwhile, Đại Việt sent missions to China which the court considered tribute missions; the Ming court enfeoffed the Vietnamese ruler as the "king of Annam", while domestically the Vietnamese used rhetoric which placed their court on equal footing with the Ming empire. However, after his death and that of his son Lê Hiến Tông (r. 1498 – 1504), the governance system of the royal family faltered. The decline began when Lê Uy Mục seized the throne of Đại Việt in 1505, murdering his grandmother and two ministers and ushering in an era of instability. The ruling Lê family, originally from Thanh Hóa in the south of Đại Việt, was increasingly dependent at court on two other leading Thanh Hóa military clans, the Trịnh and the Nguyễn. The Lê dynasty increasingly fell victim to intrigue between these competing clans. Bloodshed erupted in 1505–9, briefly forcing the Nguyễn clan back to Thanh Hóa. Extreme weather beset the kingdom in the early 16th century, with drought periods in 1503 and 1504 and typhoons and floods occurring in the Red River Delta every year from 1512 to 1517, causing a rapid decline of the economy. Instability, famines, epidemics, disasters, peasant revolts and a quick succession of eight rulers, six of whom were assassinated, led to the downfall of Đại Việt among Southeast Asian powers.

In 1527, a high-rank military officer of the weakened court, Mạc Đăng Dung, sought to restore the Hong-duc bureaucratic model. He deposed the ruling Lê monarch, Lê Cung Hoàng, and made himself ruler of Đại Việt. The Mạc kings reestablished a brief period of peace and stability over the country, promoted the restoration of Vietnamese Buddhism, and encouraged Vietnamese folk religion. In 1529 a loyalist to the old royal family, Nguyễn Kim, went to Lan Xang and submitted to King Photisarath (r. 1520 – 1547). Photisarath made Nguyễn Kim administrator of the territory of Xam Neua. In Đại Việt, Mạc Đăng Dung suppressed the Lê loyalists in Thanh Hóa, forcing the Lê remnants to seek refuge in Nguyễn Kim's domain. In 1533, Nguyễn Kim proclaimed prince Lê Duy Ninh (son of emperor Lê Chiêu Tông) as king of Đại Việt. Photisarath acknowledged this claim and allocated resources to support it. Envoys were sent to Ming China in 1536 and 1537 to denounce Mạc Đăng Dung as a usurper and to request an intervention to restore the legitimate dynasty. The Ming emperor Jiajing sent 110,000 troops to the border to invade Đại Việt. Fearing of a new Chinese invasion and the Lê revivalists, Mạc Đăng Dung and his ministers submitted themselves to the Ming. The empire reclassified their country as no longer an independent vassal state, but gave the Mạc dynasty permission to administer it as "Commissioner of Annan" (An-nan tu-t'ung shih). Đại Việt's status in the tribute system was thus reduced from that of a monarchy to a superior form of pacification commission and this lasted even after the Mạc family was overthrown in 1592.

Civil war (1545–1592)

Without Ming intervention, the Lê family slowly made their way back to power aided by members of two powerful Thanh Hóa military clans, the Nguyễn and Trịnh. This effort continued through most of the sixteenth century, and in the course of the long seesaw struggle with the Mạc a rivalry emerged between the two families, represented by their principal figures, Nguyễn Kim and Trịnh Kiểm (1503–1570). This tension developed even though the families were not merely allied militarily, but were also linked through marriage. Nguyễn Kim had married one of his daughters to Trịnh Kiểm, thus binding the two families in a time-honored fashion. Neither the military nor the marital connections, however, could forestall Trịnh Kiểm's personal ambitions. The ongoing contest for political supremacy gradually saw the Trịnh gain the upper hand, a position that was secured when the Nguyễn paterfamilias was murdered at the hands of a surrendering Mạc general in 1545. Eager to eliminate his rivals, Trịnh Kiểm arranged to have the elder Nguyễn son killed.

With the Revival Lê headquarters in Thanh Hóa now dominated by thái sư Trịnh Kiểm and the Trịnh clan, Kim's younger son, Nguyễn Hoàng, obtained advice from the scholar Nguyễn Bỉnh Khiêm that the southern frontier territory. Nguyễn Hoàng, saw in this act his own fate unless he took measures to protect himself. Through his sister, Kiểm's wife, Hoàng requested that he be appointed governor general of the distant southern frontier territories of Thuận Hoá and Quảng Nam. Remote exile of this political challenger suited the Trịnh overlord, and he agreed to the request. Shortly thereafter, in 1558, Nguyễn Hoàng entered the southern realms, marking the beginnings of a political division that would remain in effect until the Tây Sơn epoch more than two centuries later. Aided by an entourage of noble families who had joined him in exile, and who now constituted the core of a ruling elite in the new territories, Nguyễn Hoàng rapidly built up political and economic strength in the territories under his control. Nguyễn Hoàng and the Trịnh clans however, continued their joint struggles to bring back the Lê monarch back to the capital Đông Kinh (Hanoi). In 1592, they retook the Red River Delta from the Mạc, forcing the Mạc family to retreat to Cao Bằng province on the border to Ming China. It is estimated that more than 440,000 people died during this civil war. The remnants of the Mạc clan, protected by the Ming, existed in their highland enclave on the northern border, separated from the support of scholar elites in the delta lowlands of Đông Kinh.

Trịnh–Nguyễn partition In the next two centuries, the kingdom of Đại Việt was divided into two rival polities: the Trịnh lords ruled the North, known as Đàng Ngoài (Tonkin), the Nguyễn lords ruled the south, with Huế as the capital, known as Đàng Trong (Cochinchina), and the Lê monarch held the title of emperor under the control of Trịnh lords. Đại Việt enjoyed a short period of stability. Catholicism was welcomed and spread during the previous Lê–Mạc period, becaming more popular when many Jesuit missionaries arrived Vietnam after 1593. As the Manchu conquest disordered China and the availability of Chinese silk fell, Vietnamese silk began to enter the market and became an increasingly large part of the trade. Large profits could be made, and the Portuguese and Dutch endeavored to join this trade.

In 1624, Nguyễn Hoàng's son and successor, Nguyễn Phúc Nguyên, formally rejected a Trịnh demand for tax revenues, sparking the almost 45-year long (1627–1672) Trịnh-Nguyễn War, which was ultimately inconclusive. Both sides then accepted the military stalemate, and a de facto cease-fire emerged.

Trịnh Tonkin

In Tonkin, the Trịnh clan, led by Trịnh Tùng (c.1570–1623) did not seize the royal throne of Đại Việt. Having restored the Lê royal family to the throne of Đại Việt, Trịnh kept them there, married to Trịnh daughters, and maintained control of the court and the land as lords (V. chúa), not as kings. In 1674 the Trịnh called a halt to their military efforts at unification and worked instead to re-establish the Hong Duc model of governance. With the resolution of the problem of the Mạc on the northern border in Cao Bằng in 1677, diplomatic relations with the Qing dynasty settled into a predictable pattern of a tribute mission sent every three years or a double mission every six years, proceeding by land to present gold and silver objects. The result of these missions was a steady, asymmetric relationship that guaranteed Đại Việt its independence. The scholar-officials on these missions from Thang-Long absorbed the flourishing elements of Qing society during the long Kangxi reign. The Trịnh developed their agricultural base, imposed their former centralized bureaucratic model, adopted scholar values, and had formal tributary ties with the Qing dynasty. The strengths, weaknesses, and Chinese connections of each system set the political trajectories through the eighteenth century. Unlike the Lê royals and scholar-officials who embraced Confucian values, much of the general Vietnamese populace remained Buddhist. Yet the spread of Confucian ideas, ancestral rites, and the growth of shrines, especially in north Vietnam, also brought social change, affecting the roles of women. Vietnamese women enjoyed a higher degree of gender equality than any other East Asian women. Mahayana Buddhism had a major revival. Catholicism became a presence in Vietnamese society at a number of different social levels. A 1784 estimate suggests that north Vietnam had a Catholic Christian population of 350,000 to 400,000, while southern Vietnam had about 10,000 to 15,000 Christians.