The town is first mentioned in the commentaries to "Geography" by al-Idrisi in 1154 - under the name of Falamus).
In 1211 it was besieged by a joint army of Germans, Latvians and Livs.
The Sword Brethren captured the town in August 1223. A contingent of Russians The following year Volquin, their Grandmaster, built a Castle in the town. It was a major fortification of Sword Brethren and was appointed a commander from 1248.
In 1283 the town received a charter from Vilhelm von Schuborch, the master of the Order. The town was a member of the Hanseatic League from the beginning of the 14th Century.
In 1470 Johann Wolthuss von Herse, the master of the order took up residence in the castle. In 1481 Ivan II of Russia laid siege to the castle but could not take it. However during the Livonian war the Russians did seize it in 1560. During the Swedish-Polish wars at the beginning of the seventeenth century the castle changed hands several times and fell into ruin.
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.