Historical records suggest that Kandy was first established by the King Wickramabahu (1357–1374 CE) near the Watapuluwa area, north of the present city, and named Senkadagalapura at the time, although some scholars suggest the name Katubulu Nuwara may also have been used. The origin of the more popular name for the city, Senkadagala, could have been from a number of sources. These include naming after a brahmin named Senkanda who lived in a cave near the city, after a queen of King Wickramabahu named Senkanda or after a colored stone named Senkadagala.
In 1592 Kandy became the capital city of the last remaining independent kingdom in the island after the coastal regions had been conquered by the Portuguese. Several invasions by the Portuguese and the Dutch (16th, 17th and 18th century) and later by the British (most notably in 1803) were repelled.
The kingdom tolerated a Dutch presence on the coast of Sri Lanka, although attacks were occasionally launched. The most ambitious offensive was undertaken in 1761, when King Kirti Sri Rajasinha attacked and overran most of the coast, leaving only the heavily fortified Negombo intact. When a Dutch retaliatory force returned to the island in 1763, Kirti Sri Rajasinha abandoned the coastline and withdrew into the interior. When the Dutch continued to the jungles the next year, they were constantly harassed by disease, heat, lack of provisions, and Kandyan sharpshooters, who hid in the jungle and inflicted heavy losses on the Dutch.
The Dutch launched a better adapted force in January of 1765, replacing their troops' bayonets with machetes and using more practical uniforms and tactics suited to jungle warfare. The Dutch were initially successful in capturing the capital, which was deserted, and the Kandyans withdrew to the jungles once more, refusing to engage in open battle. However, the Dutch were again worn down by constant attrition. A peace treaty was signed in 1766. The Dutch remained in control of the coastal areas until 1796, when Great Britain took them over (while the Netherlands under French control) as part of the Napoleonic wars. British possession of these areas was formalized with the treaty of Amiens in 1802. The next year the British also invaded Kandy in what became known as the First Kandyan War, but were repulsed. The last ruling dynasty of Kandy were the Nayaks. Kandy stayed independent until the early 19th century. In the Second Kandyan War, the British launched an invasion that met no resistance and reached the city on February 10, 1815. On March 2, 1815, a treaty known as the Kandyan Convention was signed between the British and the Radalas (Kandyan aristocrats). With this treaty, Kandy recognized the King of England as its King and became a British protectorate. The last king of the kingdom Sri Vikrama Rajasinha was captured and taken as a royal prisoner by the British to Vellore Fort in southern India along with all claimants to the throne.
As the capital, Kandy had become home to the relic of the tooth of the Buddha which symbolizes a 4th-century tradition that used to be linked to the Sinhalese monarchy, since the protector of the relic was the ruler of the land. Thus the Royal Palace and the Temple of the Tooth were placed in close proximity to each other.