Born on 8 February 1762, he also had two other names in his childhood: Nguyễn Phúc Chủng (阮福種) and Nguyễn Phúc Noãn (阮福暖). Nguyễn Ánh was the third son of Nguyễn Phúc Luân and Nguyễn Thị Hoàn. Luan was the second son of Lord Nguyễn Phúc Khoát of southern Vietnam—the first son had already predeceased the incumbent Lord. There are differing accounts on which son was the designated successor. According to one theory, Luân was the designated heir, but a high-ranking mandarin named Trương Phúc Loan changed Khoat's will of succession on his deathbed, and installed Luan's younger brother Nguyễn Phúc Thuần—who was the sixteenth son—on the throne in 1765. Luan was jailed and died in the 1765, the same year as Thuan's installation. However, the historian Choi Byung Wook claims that the notion that Luân was the designated heir was based on fact but was propagated by 19th century Nguyễn Dynasty historians after Nguyễn Ánh had taken the throne as Gia Long to establish the emperor's legitimacy. According to Choi, Lord Khoát had originally chosen the ninth son, who then died, leaving Loan to install Lord Thuần. At the time, the alternative was the eldest son of the ninth son, Nguyễn Phúc Dương, whom opposition groups later tried unsuccessfully to convince to join them as a figurehead to lend legitimacy. In 1775, Thuan was forced to share power with Dương by military leaders who supported the Nguyêns. At this time, Nguyễn Ánh was a minor member of the family and did not have any political support among court powerbrokers.
However, Thuan lost his position as lord of southern Vietnam and was killed—along with Duong—during the Tây Sơn rebellion led by the brothers Nguyễn Nhạc, Nguyễn Huệ and Nguyễn Lữ in 1777. Nguyễn Ánh was the most senior member of the ruling family to have survived the Tây Sơn victory, which pushed the Nguyễn from their heartland in central Vietnam, southwards towards Saigon and into the Mekong Delta region in the far south. This turn of events changed the nature of the Nguyễn power hierarchy; the family and the first leader Nguyễn Hoàng had originally come from Thanh Hoa Province in northern Vietnam, and this is where most of their senior military and civil leadership's heritage derived from, but as a result of the Tây Sơn's initial successes, much of this old power base was destroyed and Nguyễn Ánh had to rebuild his support network among southerners, who later became the core of the regime when the Nguyễn Dynasty was established.
Nguyễn Ánh was sheltered by a Catholic priest
Paul Nghi (Phaolô Hồ Văn Nghị) in Rạch Giá. Later, he fled to Hà Tiên on the southern coastal tip of Vietnam, where he met Pigneau de Behaine, a French priest who became his adviser and played a major part in his rise to power. Receiving information from Paul Nghi, Pigneau avoided the Tay Son army in Cambodia, and came back to assist Nguyễn Ánh. They hid in the forest to advoid the pursuit of Tay Son army. Together, they escaped to the island of Pulo Panjang in the Gulf of Siam. Pigneau hoped that by playing a substantial role in a Nguyễn Ánh victory, he would be in position to lever important concessions for the Catholic Church in Vietnam, helping its expansion in South East Asia.
Pigneau de Behaine, the French priest who recruited armies for Nguyễn Ánh during the war against the Tây Sơn.
In late 1777, the main part of the Tây Sơn army left Saigon to go north and attack the Trịnh lords, who ruled the other half of Vietnam. Nguyễn Ánh stealthily returned to the mainland, rejoining his supporters and reclaimed the city. He was crucially aided by the efforts of Do Thanh Nhon, a senior Nguyễn Lord commander who had organized an army for him, which was supplemented by Cambodian mercenaries and Chinese pirates. The following year, Nhon expelled further Tây Sơn troops from the surrounding province of Gia Dinh, and inflicted heavy losses on the Tây Sơn naval fleet. Taking advantage of the more favorable situation, Nguyễn Ánh sent a diplomatic mission to Siam to propose a treaty of friendship. However, this pact was derailed in 1779 when the Cambodians held an uprising against their pro-Siamese leader
Ang Non. Nguyễn Ánh sent Nhon to help the uprising, which saw Ang Non defeated decisively and executed.
Nhon returned to Saigon with high honor and concentrated his efforts on improving the Nguyễn navy. In 1780, in an attempt to strengthen his political status, Nguyễn Ánh proclaimed himself Nguyễn vương (Nguyễn king or Nguyễn ruler in Vietnamese), with the support of Nhon's Dông Sơn Army. Then, in 1781, Nguyễn Ánh sent further forces to prop up the Cambodian regime against Siamese armies who wanted to reassert their control. Shortly thereafter, Nguyễn Ánh had Nhon brutally murdered. The reason remains unclear, but it was postulated that he did so because Nhon's fame and military success was overshadowing him. At the time, Nhon had much, if not dominant power, behind the scenes. According to later Nguyễn Dynasty chronicles, Nhon's powers included that of deciding who would receive the death penalty, and allocating budget expenditures. Nhon also refused to allocate any money for royal spending, and both he and his men were reported to have acted in an abrasive and disrespectful manner to Nguyễn Ánh.
The Tây Sơn brothers reportedly broke out in celebration upon hearing of Nhon's execution, as Nhon was the Nguyễn officer that they feared the most. Large parts of Nhon's supporters rebelled, weakening the Nguyễn army, and within a few months, the Tây Sơn had recaptured Saigon mainly on the back of naval barrages. Nguyễn Ánh was forced to flee to Ha Tien, and then onto the island of Phu Quoc. Meanwhile, some of his forces continued to resist in his absence. While the murder of Nhon weakened Nguyễn Ánh in the short term, as many southerners who were personally loyal to Nhon broke away and counter-attacked, it also allowed Nguyễn Ánh to gain autonomy and then take steps towards exerted direct control over the remaining local forces of the Dong Son who were willing to work with him. Nguyễn Ánh also benefited from the support of Chau Van Tiep, who had a power base in the central highlands between the strongholds of the Nguyễn and the Tây Sơn.
In October 1782, the tide shifted again, when forces led by
Nguyễn Phúc Mân, Nguyễn Ánh's younger brother, and Chau Van Tiep drove the Tây Sơn out of Saigon. Nguyễn Ánh returned to Saigon, as did Pigneau The hold was tenuous, and a counterattack by the Tây Sơn in early 1783 saw a heavy defeat to the Nguyễn, with Nguyen Man killed in battle. Nguyễn Ánh again fled to Phu Quoc, but this time his hiding place was discovered. He managed to escape the pursuing Tây Sơn fleet to Koh-rong island in the Bay of Kompongsom. Again, his hideout was discovered and encircled by the rebel fleet. However, a typhoon hit the area, and he managed to break the naval siege and escape to another island amid the confusion. In early-1784, Nguyễn Ánh went to seek Siamese aid, which was forthcoming, but the extra 20,000 men failed to weaken the Tây Sơn's hold on power. This forced Nguyễn Ánh to become a refugee in Siam in 1785.[note 3] To make matters worse, the Tây Sơn regularly raided the rice growing areas of the south during the harvesting season, depriving the Nguyễn of their food supply. Nguyễn Ánh eventually came to the conclusion that using Siamese military aid would generate a backlash amongst the populace, due to prevailing Vietnamese hostility towards Siam.