First records of civilization in the surroundings of Viljandi date back to the 5th millennium B.C. The first written record of the earthen stronghold of Viljandi was in the year 1154 in the commentaries to al-Idrisi’s world atlas “Geography”.
In the 12th century a permanent settlement emerged around the stronghold of Viljandi, which also became the economic centre of the ancient Sakala district.
After the fight for freedom in the first quarter of the 13th century Viljandi fell under the rule of the Order of the Brethren of the Sword (later the Livonian Order) and in place of the Sakala wooden stronghold a powerful Order Centre was started in 1224.
In the 13th century a medieval town arose on the northern side of the stronghold. The Hamburg-Riga town bylaws, lands and population of it were first recorded in 1283. During the first half of the 14th century Viljandi joined the influential Hanseatic League – the town had become an important stop for merchants on their way to Russia and back. In 1365 the town council was party when peace between Denmark and Hansa was concluded.
In the Middle Ages Viljandi was a typical small commercial town, which got its main income from transit trade. The local trade and handicraft played an equally important role. The decline of Viljandi started during the Livonian War. In 1560 the forces of Prince Kurbski demolished the town and the stronghold.
During the Polish-Russian wars in the first quarter of the 17th century the town and the stronghold were completely destroyed. Under the Swedish rule in the 17th century the town bylaws of Viljandi were cancelled.
After the Great Northern War the Russians seized the power and Viljandi was without laws until the year 1783, when in the course of the regency reforms of Catherine II Viljandi became a district town. This involved the re-establishment of town bylaws. The economic and political importance of Viljandi started to increase. The population, meanwhile having decreased to the minimum, started to rise again, handicraft, trading and cultural life were enlivened.