The Livonian War  was fought for control of Old Livonia , when the Tsardom of Russia faced a varying coalition of Denmark-Norway, the Kingdom of Sweden, and the Union  of the Grand Duchy of Lithuania and the Kingdom of Poland. During the period 1558-1578, Russia dominated the region with early military successes at Dorpat  and Narva. Russian dissolution of the Livonian Confederation brought Poland-Lithuania into the conflict, while Sweden and Denmark both intervened between 1559 and 1561. Swedish Estonia was established despite constant invasion from Russia, and Frederick II of Denmark bought the old Bishopric of Ösel-Wiek, which he placed under the control of his brother Magnus of Holstein. Magnus attempted to expand his Livonian holdings to establish the Russian vassal state Kingdom of Livonia, which nominally existed until his defection in 1576. In 1576, Stefan Batory became King of Poland as well as Grand Duke of Lithuania and turned the tide of the war with his successes between 1578 and 1581, including the joint Swedish-Polish-Lithuanian offensive at the Battle of Wenden. This was followed by an extended campaign through Russia culminating in the long and difficult siege of Pskov. Under the 1582 Truce of Jam Zapolski, which ended the war between Russia and Poland-Lithuania, Russia lost all its former holdings in Livonia and Polotsk to Poland-Lithuania. The following year, Sweden and Russia signed the Truce of Plussa with Sweden gaining most of Ingria and northern Livonia while retaining the Duchy of Estonia.
Question: What event happened first, Magnus's defection, or the Truce of Jam Zapolski?
Answer: until his defection in 1576. | Magnus attempted to expand