From 1780, the Gurkhas made several attempts to capture the entire region of Darjeeling. By the beginning of the 19th century, they had overrun Sikkim as far eastward as the Teesta River and had conquered and annexed the Terai and the entire area now belonged to Nepal. In the meantime, the British Army was engaged in preventing the Gurkhas from over-running the whole of the northern frontier. The Anglo-Nepalese War broke out in 1814, which resulted in the defeat of the Gurkhas and subsequently led to the signing of the Sugauli Treaty in 1816. According to the treaty, Nepal had to cede all those territories annexed from the Chogyal of Sikkim to the British East India Company (i.e. the area between Mechi River and Teesta River). Later in 1817, through the Treaty of Titalia, the British East India Company reinstated the Chogyal of Sikkim, restored all the tracts of land between the River Mechi and the River Teesta to the Chogyal of Sikkim and guaranteed his sovereignty.