himself Emperor in 1778. A conflict with the Trịnh thus became unavoidable. Conflict with Siam 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. Conquest of Trịnh lords 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. War with the Qing dynasty, ending the Lê dynasty 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: 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