People lived in this valley long before any Spanish town. The earliest archaeological traces turn up around El Infiernito, and the Muisca held the land when the conquistadors arrived, under the zaque of Hunza. The Muisca trace their origin to Bachue, a woman who came out of a lake in the Iguaque mountains with her young son. They were skilled farmers, potters and astronomers, and you can still see their interest in the sky at El Infiernito.
The Spanish founded the town on 12 June 1572. Captain Hernán Suárez de Villalobos did it on the orders of Andrés Díaz Venero de Leyva, the colony's first president, whose name the town still carries. The first site was close to the Muisca observatory, in the Zaquencipá valley. Twelve years later the town moved to where it stands today.
Under Spanish rule the valley produced olive oil and cereals, mostly wheat and barley. Spanish families liked it as a place to settle, and viceroys came to rest.
Then the world moved on elsewhere. The town sat away from the main trade routes, in a dry high valley with no minerals worth digging. That is why you now walk on cobbles between sixteenth-century houses. A road to Tunja by way of Arcabuco was begun only in 1830, and the town's growth is dated from it.
Independence left its mark on the plaza and the streets around it. On 4 October 1812 the United Provinces of Nueva Granada held their first congress in a house on the north corner of the square. Antonio Ricaurte, born in town in 1797, fought as a captain under Simón Bolívar and died in 1814 at San Mateo, in present-day Venezuela. Antonio Nariño, who had translated the Rights of Man into Spanish, spent his last years here and died in the town.
In 1954 the state declared the town a National Monument, which fixed its look in place. The houses of Nariño and the painter Luis Alberto Acuña are now museums. Acuña spent his last years here and died in 1993, and his house holds some of his work, including two murals in the inner patio. Colombia's Air Force bought Ricaurte's birthplace in 1977 and turned it into a military museum.
In 2010 Villa de Leyva joined the first group of eleven Pueblos Patrimonio, Colombia's heritage towns, and Colombia has put it forward as a candidate for UNESCO World Heritage listing. Bogotá residents come for weekends, and a growing number of foreign visitors come too.