Bhaktapur's historical roots lie in its position on the early trade route to Tibet, though the credit for the formal founding of the city goes to King Ananda Malla in the 12th century. The oldest part of the town is around Tachupal Tole, to the east.
From the 14th to the 16th century, as Bhaktapur became the most powerful of the valley's three Malla kingdoms, the focus of the town shifted west to the Durbar Sq area. Much of the town's great architecture dates from the rule of King Yaksha Malla (1428-82), who built the Pashupatinath and Dattatreya temples, but also from the end of the 17th century, during King Bhupatindra Malla's reign. At its peak the city boasted 172 temples and monasteries, 77 water tanks, 172 pilgrim shelters and 152 wells.
The 15th-century royal palace in Durbar Sq remained the seat of power until the city's defeat by Prithvi Narayan Shah in 1768 relegated the former capital to a market town. The 1934 earthquake caused major damage to the city.