The Tây Sơn dynasty (Vietnamese: [təj ʂəːn], Vietnamese: Nhà Tây Sơn, Chữ Nôm: 茹西山, lit. 'House of Tây Sơn'; Vietnamese: triều Tây Sơn (chữ Hán: 朝西山), officially Great Việt (Vietnamese: Đại Việt; Chữ Hán: 大越), was a dynasty of Vietnam. It was founded after three Nguyễn brothers from the village of Tây Sơn rebelled against the Lê dynasty, Nguyễn lords, and Trịnh lords. The Tây Sơn were led by these three brothers, referred to by modern Vietnamese historians as the Tây Sơn brothers because of their origin in the district of Tây Sơn. The Tây Sơn was later succeeded by the Nguyễn dynasty.
 The Tây Sơn dynasty ended the century-long war between the Trịnh and Nguyễn families, ended the Lê dynasty, and united the country for the first time in 200 years. The Tây Sơn entered a tributary relationship with the Qing dynasty of China and gained the recognition as the official rulers of Vietnam from the Qianlong Emperor. Under the most prominent of the Tây Sơn brothers, Nguyễn Quang Bình—later the emperor Quang Trung—Vietnam experienced an age of relative peace and prosperity. However, his heir was not capable of properly ruling the country, allowing the exiled Nguyễn lord Nguyễn Ánh to retake the south of Vietnam and eventually pave the way for his own imperial dynasty, the Nguyễn dynasty.
 The Tây Sơn dynasty was named after the Tây Sơn district in Bình Định province, the birthplace of the three brothers who established the dynasty. The name "Tây Sơn" means "western mountains" from Chinese 西山 Xīshān where 西 xi means west and 山 shan means mountain.
 In the 18th century, Vietnam was de jure ruled by the Lê dynasty, but real power lay in the hands of two warring families, the Trịnh lords of the north who ruled from the imperial court in Thăng Long and the Nguyễn lords in the south, who ruled from their capital Huế. Both sides warred extensively for control of the country. Life for the peasants during these times were difficult: ownership of land became concentrated in the hands of a handful of landlords as time passed. The imperial bureaucracy became corrupt and oppressive; at one point the imperial examination-degrees were sold to whoever was wealthy enough to purchase them. As the people grew poorer, the ruling lords lived lavish lifestyles in opulent palaces. While the Trịnh lords had enjoyed peace since the end of the war between the Trịnh and the Nguyễn in 1672, the Nguyễn lords regularly campaigned against Cambodia and later the Kingdom of Siam (Thailand). While the Nguyễn lords usually won these wars and opened up new fertile lands for the landless poor to settle, the frequent warring cost money, resources, and lives.
 In 1769 the new king of Siam Taksin launched a war to regain control of Cambodia. The war went against the Nguyễn lords, and they were forced to abandon some of the newly conquered lands, which included the Principality of Hà Tiên in the eastern coast of Cochinchina. Lord Nguyễn Phúc Khoát died in 1765, the court power was transferred to regent Trương Phúc Loan, creating a political crisis. This coupled with heavy taxes and endemic corruption at the local level spurred three brothers Nguyễn Nhạc, Nguyễn Huệ, and Nguyễn Lữ (not related to the Nguyễn lords) from the village of Tây Sơn, central Vietnam, to revolt in 1771 against the Nguyễn lord Phúc Thuần.
 The Tây Sơn brothers styled themselves as champions of the people. Over the next year, the revolt gained traction and they won some battles against the Nguyễn army that was sent to crush their rebellion. The Tây Sơn drew their support from not only poor farmers but also by some indigenous highland tribes. Nguyễn Huệ, the brothers' leader, said that his goal was to end the people's oppression, reunite the country, and restore the power of the Lê emperor in Hanoi. The Tây Sơn also promised to remove corrupt officials and redistribute land.
 In 1773 the Tây Sơn captured the port of Qui Nhơn, where the merchants, who had suffered under restrictive laws put in place by the Nguyễn, lent the uprising their financial support. The Nguyễn, at last recognizing the serious scale of the revolt, made peace with the Siamese, giving up some land they had conquered in previous decades. However, their problems were compounded when Trịnh Sâm chose to end the 100-year peace and exploit the turmoil in the south by sending his army to attack Phú Xuân (modern-day Huế), the Nguyễn capital. The Trịnh army captured the city, forcing the Nguyễn to flee to Gia Định (now modern day Saigon).
 The Trịnh army continued to march south and the Tây Sơn army continued its conquest of other southern cities. The forces arrayed against the Nguyễn were simply too many and in 1776 the Tây Sơn army captured the last Nguyễn stronghold of Gia Định and massacred the town's Chinese population. The entire Nguyễn family was killed at the end of the siege, except for one nephew, Nguyễn Ánh, who managed to escape to Siam. The eldest Tây Sơn brother, Nguyễn Nhạc, proclaimed himself Emperor in 1778. A conflict with the Trịnh thus became unavoidable.
 The Tây Sơn spent the next decade consolidating their control over the former Nguyễn territory. Nguyễn Ánh proved to be a stubborn enemy. He convinced the King of Siam, P'ya Taksin, to invade Vietnam in support of him. The Siamese army attacked in 1780, but in several years of warfare, it was unable to defeat the Tây Sơn army, as gains were followed by losses. In 1782, the Siamese king was killed in a revolt, and less than a year later, Nguyễn Ánh's forces were driven out of Vietnam. In 1785, Siam launched an invasion again and occupied part of the Mekong Delta, but was defeated by Nguyen Hue in the Battle of Rạch Gầm-Xoài Mút.
 Having vanquished the Nguyễn for the time being, Nguyễn Huệ decided to destroy the power of the Trịnh lords. He marched to the north at the head of a large army in 1786, and after a short campaign, defeated the Trịnh army successfully. The Trịnh were also unpopular and the Tây Sơn army seemed invincible. The Trịnh lord fled north into China. Nguyễn Huệ later married princess Lê Ngọc Hân, the daughter of the nominal later Lê Emperor, Lê Hiển Tông.
 A few months later, realising that his hope of retaining power had gone, the Emperor Lê Chiêu Thống fled north to the Qing Empire of China, where he formally petitioned the Qianlong Emperor for aid. The Qianlong Emperor agreed to restore Lê Chiêu Thống to power, and so in 1788, a large Qing army marched south into Vietnam and captured the capital Thăng Long.
 Nguyễn Huệ gathered a new army and prepared to fight the Qing army. He addressed his troops before the battle saying:[citation needed]
 The Qing have invaded our country and occupied the capital city, Thăng Long. In our history, the Trưng Sisters fought against the Han, Đinh Tiên Hoàng against the Song, Trần Hưng Đạo against the Mongol Yuan, and Lê Lợi against the Ming. These heroes did not resign themselves to standing by and seeing the invaders plunder our country; they inspired the people to fight for a just cause and drive out the aggressors... The Qing, forgetting what happened to the Song, Yuan and Ming, have invaded our country. We are going to drive them out of our territory. In a surprise attack, while the Qing army was celebrating the Lunar New Year, Nguyễn Huệ's army defeated them at the Battle of Ngọc Hồi-Đống Đa and forced them, along with Lê Chiêu Thống, to retreat. The Tay Son were supported by Chinese pirates. Anti-pirate activities were undertaken by a joint alliance between the Qing dynasty and Nguyễn lords Gia Long while Chinese pirates collaborated with the Tay Son.
 After the battle, Nguyễn Huệ sought to restore the tributary relationship in order to deter a joint Qing-Siam pincer attack and prevent further Qing Chinese attempts to restore the Lê dynasty. Nguyễn Huệ sent a ritually submissive request to the Qianlong Emperor under the name of Nguyễn Quang Bình (also referred to as Ruan Guangping).
 In 1789, the Qianlong Emperor agreed to re-establish the tributary relationship and enfeoff Nguyễn as the King of Annam on the condition that Nguyễn Huệ personally lead a special delegation to Beijing to celebrate the Qianlong Emperor's 80th birthday. For the Qianlong Emperor, the motivation for accepting the arrangement was to retain the Qing's supremacy and stabilize their southern border. Chinese and Vietnamese sources agreed that Nguyễn Huệ sent an imposter with a delegation to Beijing, where they were received with lavish imperial favors. The Qianlong Emperor approved the proposal and bestowed Nguyễn Huệ with the title An Nam quốc vương ("King of Annam"). The title indicated that Nguyễn Huệ was recognized as the legal ruler of Vietnam and Lê Chiêu Thống was no longer supported.
 Quang Trung, was resentful. He trained his army, built large warships and waited for an opportunity to take revenge. He also provided refuge to organizations such as the Tiandihui and the White Lotus. Chinese pirates, such as Chen Tien-pao (陳添保), Mo Kuan-fu (莫觀扶), Liang Wen-keng (梁文庚), Fan Wen-tsai (樊文才), Cheng Chi (鄭七) and Cheng I (鄭一) were granted official positions and noble ranks under the Tây Sơn empire. All attack plans had to be given up due to Nguyễn Huệ's sudden death. The attack never materialized by the time that Quang Trung died in 1792.
 After the Tây Sơn massacred ethnic Han Chinese settlers in 1782, the support of the Qing Chinese shifted towards to the Nguyễn lords.
 After Quang Trung's death, his son Nguyễn Quang Toản was enthroned as Emperor Cảnh Thịnh at the age of ten. However, the real power was in the hands of his uncle Bui Dac Tuyen, who enacted a massive political purge. Many who served under Quang Trung were executed, while others became discouraged and left the regime, considerably weakening the Tây Sơn. This paved the way for Nguyễn Ánh to capture the entire country within 10 years, with the help of French military adventurers enlisted by French bishop Pigneau de Behaine. In 1800, Nguyễn Ánh occupied Quy Nhơn citadel. In 1801, he occupied Phú Xuân, forcing Nguyễn Quang Toản to flee to Thăng Long. In 1802, Ánh besieged Thăng Long. The then 20-year-old Nguyễn Quang Toản escaped, but then was captured and executed, ending the dynasty after 24 years, and the Nguyễn, the last imperial dynasty of Vietnam, took over the country in 1802. 
 The Nguyễn lords eventually defeated the Tây Sơn dynasty, took complete control of Vietnam, and established the imperial Nguyễn dynasty in 1802. The Nguyễn executed the defeated Tây Sơn leader Bùi Thị Xuân by crushing the body with an elephant. The heart and liver from her body were consumed by soldiers of the Nguyễn.