Why did Nepal remain independent from the British Raj?

by Twiggyyy

Was it because Britain tried and failed to take it or a more diplomatic reason?

Rhurtle

The British did not need to, did not want to, and did not have to colonize Nepal.

The primary interest the British East India Company had in Nepal was for the potential for trade with Tibet and China through its many trans-Himalayan passes — the ruling Gurkha kingdom at this time controlled most of the Central Lesser Himalayas and wanted all trade to be channeled through them.

With the Anglo-Gurkha War (1814-16), the EIC gained control of what are now the Indian states of Himachal Pradesh and Uttarakhand and could trade with Tibet and China directly through either these regions or the restored regions of the kingdom of Sikkim. But by the 1840s this trade had become pointless — Tibet was no longer a profitable source of wool or borax, especially since the trans-Himalayan passages weren't all that great for trading; and the Opium Wars would give the British a direct foothold in China.

The Treaty of Segauli, signed at the end of the war, also established a permanent British Residency in the capital of Kathmandu, and the Residents would become important political forces at the court. But this was fundamentally different from most British Residencies in the Indian Princely States since the Gurkhas had no obligations towards the British, other than not employing Europeans.

So, by 1846, while the Gurkhas was still perceived as a military threat to British India, the Gurkha court was generally (though not completely) in favor of a concord. More importantly, for the British, it had become a friendly-ish buffer state between British India and Qing China — it was in the British sphere of influence.

The ascendency of the Ranas in 1846 under Rana Jang Bahadur furthered this concord since he saw cooperation as the only way for Nepal to avoid absorption into British India. He would offer support during the Second Anglo-Sikh War (1848-9), traveled to England as ambassador in 1850, profitably supplied timber to the British, used his military to actively assist the British during the events of 1857, and more famously began to allow 'Gurkhas' to serve in the British military. The way in which he came to power, through the Kot Massacre, also made the British an important ally against other factions at the Nepalese court. The Ranas continued to provide help to the British, sending soldiers to assist in the quelling of the Boxer Rebellion, the Younghusband Expedition to Tibet (1903-4), and the First World War.

However, it should be noted the British in this period never really declared Nepal to be a completely independent state. Lord Curzon, Viceroy of India, would write in 1903:

It does not seem to be necessary to define the precise nature of our protectorate. It is less stringent than our relations with other native states; it is more stringent than our treaty protectorate over Afghanistan. It approximates perhaps more closely to our connection with Bhutan than with any other native state... Nepal should be regarded as falling under our exclusive political influence and control.

It was only in 1920, as the relations between the two were at their zenith, that the Resident was turned into an Envoy, and the Residency into a Legation, and the British for the first time acknowledged the Nepalese state as an independent entity:

This decision is intended to emphasize the unrestricted independence of the Kingdom of the Gorkhas, which is on an entirely different footing from that of the Protected States of India.

This then finally led to the Nepal-British Treaty of 1923, which began:

There shall be perpetual peace and friendship between the Governments of Great Britain and Nepal, and the two Governments agree mutually to acknowledge and respect each other's independence, both internal and external. [PDF of the Treaty]

Sources: I can't claim to have kept up with newer writings on the subjects, especially by Nepalese scholars. My answer is mostly drawn from Nepal: Strategy for Survival by Leo Rose (1971); Political Relations between India and Nepal: 1877-1923 by K. Mojumdar (1973); Anglo-Nepalese Relations: from the Earliest Times of the British Rule In India till the Gurkha War by K. C. Chaudhuri; and Kings, Soldiers and Priests: Nepalese Politics and the Rise of Jang Bahadur Rana by John Whelpton (1991).

The Invasion of Nepal: John Company at War by John Pemble (1971) gives a good account of the Anglo-Gurkha War; in 2009 he wrote an article, "Forgetting and Remembering Britain's Gurkha War" (Asian Affairs vol. 40 no. 3) which goes over the public memory of the war, which had not gone all that well for the British despite their victory. Finally, E T Atkinson's The Himalayan Gazetteer (1882) is the most comprehensive primary source (from a British point-of-view) for the Central Lesser Himalayas.