Despite a humiliating defeat to China after a failed invasion of Tibet in the 1790s, which led to Nepal becoming a tributary state of the Chinese Empire, Nepal successfully consolidated its territories in the ensuing years. During the early-nineteenth century, however, the expansion of the East India Company's rule in India led to the Anglo-Nepalese War (1814–1816), which resulted in Nepal's defeat. Under the Sugauli Treaty, the kingdom retained its independence, but became a de facto protectorate of Britain in exchange for territorial concessions equating to a third of the territory then under Nepalese rule, sometimes known as "Greater Nepal". Political instability following the war resulted in the ascendancy of the Rana dynasty, which made the office of Prime Ministers of Nepal hereditary in their family for the next century, from 1843 to 1951. Beginning with Jung Bahadur, the first Rana ruler, the Rana dynasty reduced the Shah monarch to a figurehead role. Rana rule was marked by tyranny, debauchery, economic exploitation and religious persecution.[5][6]
The mid-twentieth century began an era of moves towards the democratisation of Nepal. In 1923, Britain formally recognised Nepalese sovereignty and ended its protectorate, but continued to exercise political influence through the Rana rulers and its rule in India, which ended in 1947. In July 1950, the newly independent republic of India signed a friendship treaty in which both nations agreed to respect the other's sovereignty. In November of the same year, India played an important role in supporting King Tribhuhvan, whom the Rana leader Mohan Shamsher Jang Bahadur Rana had attempted to depose and replace with his infant grandson King Gyanendra. With Indian support for a new government consisting largely of the Nepali Congress, King Tribhuvan ended the rule of the Rana dynasty in 1951.
Unsuccessful attempts were made to implement reforms and a constitution during the 1960s and 1970s. An economic crisis at the end of the 1980s led to a popular movement which brought about parliamentary elections and the adoption of a constitutional monarchy in 1990. The 1990s saw the beginning of the Nepalese Civil War (1996–2006), a conflict between government forces and the insurgent forces of the Communist Party of Nepal (Maoist). The situation for the Nepalese monarchy was further destabilised by the 2001 Nepalese royal massacre, in which Crown Prince Dipendra reportedly shot and killed ten people, including his father King Birendra, and was himself mortally wounded by what was allegedly a self-inflicted gunshot.
As a result of the massacre, King Gyanendra returned to the throne. His imposition of direct rule in 2005 provoked a protest movement unifying the Maoist insurgency and pro-democracy activists. He was eventually forced to restore Nepal's House of Representatives, which in 2007 adopted an interim constitution greatly restricting the powers of the Nepalese monarchy. Following an election held the next year, the Nepalese Constituent Assembly formally abolished the kingdom in its first session on 28 May 2008, declaring the Federal Democratic Republic of Nepal in its place.