Prithvi Narayan Shah ascended the throne of the Gorkha Kingdom in 1743 after the death of his father Nara Bhupal Shah. He founded Nepal after invading Nuwakot in 1744 which started the unification process of the present-day country of Nepal. Shah died on 11 January 1775 after ruling for over 31 years; by the end of his reign, he had won over Nuwakot, Makwanpur, and Nepal Valley. Upon Prithvi Narayan's death, his son Pratap Singh Shah was appointed as the king. He died prematurely at the age of 26 in 1777; on the same day, his young son, Rana Bahadur Shah, became king with his mother, Queen Rajendra, and later his uncle, Bahadur Shah, as regent. Later Rana Bahadur abdicated the throne and his illegitimate son Girvan Yuddha Bikram Shah became the king. During the reign of Girvan, the Anglo-Nepalese War broke out, which ended with the signing of the Treaty of Sugauli in 1816, resulting in Nepal losing a third of its territory. The king died on 20 November 1816 after contracting smallpox. Rajendra Bikram Shah succeeded his father at the age of three under the regency of his step-grandmother Queen Lalita Tripura Sundari Devi and Prime Minister Bhimsen Thapa. He declared that he would rule Nepal only with the advice of Rajya Lakshmi Devi and handed her all of his powers which led to the Kot massacre in 1846. After the massacre, Jung Bahadur Rana rose to power and "de facto" ruled the country and started the Rana dynasty who ruled the country for over a century. The next year, Rajendra was imprisoned by Jung Bahadur at Hanuman Dhoka and his son Surendra Bikram Shah ascended the throne. His powers were limited; he died in 1881, three years after his eldest son, Trailokya. Surendra's grandson Prithvi Bir Bikram Shah became the king, but like his grandfather, he did not have many powers. Prithvi died prematurely at the of 36 and his five-year-old son, Tribhuvan, succeeded him.