The Kingdom of Livonia was a nominal state in what is now the territory of Estonia and Latvia. The Russian Tsar Ivan IV declared the establishment of the kingdom during the Livonian War of 1558-1583, but it never functioned properly as a polity. On June 10, 1570 the Danish Duke Magnus of Holstein arrived in Moscow, where he was crowned King of Livonia. Magnus took the oath of allegiance to Ivan as his overlord and received from him the corresponding charter for the vassal kingdom of Livonia in what Ivan termed his patrimony. The treaty between Magnus and Ivan IV was signed by an oprichnik and by a member of the zemskii administration, the d'iak Vasiliy Shchelkalov. The territories of the prospective new kingdom still had to be conquered, but nevertheless Põltsamaa Castle was proclaimed the future official residence of the king. The new king Magnus of Livonia departed from Moscow with 20,000 Russian soldiers for the conquest of Swedish-controlled Reval. Ivan's hope for the support of King Frederick II of Denmark, the older brother of Magnus, failed. By the end of March 1571 Magnus gave up the struggle for Reval and abandoned the siege.
In 1577, having lost Ivan's favor and getting no support from his brother, Magnus called on the Livonian nobility to rally to him in a struggle against foreign occupation. Ivan's forces attacked him and took him prisoner. On his release he renounced his royal title. Magnus spent the last six years of his life at the castle of Pilten in the Bishopric of Courland where he died (March 1583) as a pensioner of the Polish crown.
The end of the Livonian War in August 1583 saw most of the territory of Old Livonia (Duchy of Courland and Semigallia and Duchy of Livonia) under the control of the Polish–Lithuanian Commonwealth, with Swedish control established in the Duchy of Estonia.