During the war with the Teutonic Order of 1294–95, the Lithuanians used the
Wizna castle of the Masovian Duke
Wenceslaus of Płock on the lower bank of the
Vistula. After the
King of Bohemia John of Luxembourg forced the Masovian dukes to support the Teutonic Order again, the Lithuanians led by
Dovydas Gardiniškis ravaged
Pułtusk, the estate of the
Bishop of Płock, in 1324. At the beginning of the 14th century,
Władysław I Łokietek united part of the Polish lands. The common threat from the Teutonic Order prompted him to conclude an alliance with the Lithuanian prince
Gediminas in 1325. The alliance was strengthened by the marriage of Władysław's successor,
Casimir III the Great, the future king, to the grand duke's daughter,
Aldona of Lithuania. In early 14th century, the
Grand Duke of Lithuania Vytenis regained part of the Yotvingian lands in
Podlachia from Masovian control, which had been ravaged, captured and divided by Masovia, Volhynia and the Teutonic Order at the end of the 13th century. In the second half of the 1320s–mid-1350s, Masovia was neutral with regards to Lithuania. Wenceslaus married Danutė Gediminaitė, the daughter of the Grand Duke of Lithuania
Gediminas, in 1321. In 1323, Gediminas assisted the Masovian dukes in their fight with the Teutonic Order over
Dobrzyń. In 1331,
Yuri II Boleslav, the Duke of Masovia as well as
Galicia–Volhynia (Traidenis' grandson), married another daughter of Gediminas, Euphemia Gediminaitė. Through Masovia, Gediminas maintained relations with
Western Europe and invited foreigners to travel to Lithuania through its lands. In the summer of 1337, the Masovian knights defeated the Lithuanian troops crossing the
Narew River in the .
Galicia–Volhynia Wars During the reign of Casimir the Great, fighting flared up again, as both sides sought to take over the
Kingdom of Galicia–Volhynia. The war for the principality, the
Galicia–Volhynia Wars, were fought intermittently in the years 1340–1366, ended with the division of its territories. In the mid and late 14th century, Masovia assisted its
suzerain Poland (especially its king
Casimir III the Great) during its battles with Lithuania over Galicia–Volhynia. In 1349, 1368–79, Lithuania launched retaliatory campaigns against Masovia. Later, wars with Masovia were fought over the Lithuanian lands in
Podlachia. The Masovian Duke
Janusz I the Old (who married
Kęstutis' daughter Danutė Kęstutaitė ), taking advantage of Kęstutis's struggle with the Grand Duke of Lithuania
Jogaila, occupied Podlachia in 1382;
Vytautas the Great recaptured it in 1383. Jogaila, who became King of Poland in 1386, attracted the Duke
Siemowit IV of Masovia to his side by marrying of his sister
Alexandra of Lithuania in 1388. This also succeeded in restoring traditional dynastic ties between Masovia's
Piast dynasty and the
Gediminids. After the death of Casimir the Great, in 1370 the Lithuanians attacked and occupied the duchies of Volodymyr,
Belz and Chełm. This was the last major Lithuanian invasion. In 1377 King
Louis I of Hungary organized an expedition to regain the lost lands. During the time of
Jadwiga of Poland, talks began between Polish representatives and the Lithuanian prince
Jogaila about an alliance between Poland and Lithuania, due to the threat to both countries from the Teutonic Knights. In 1385, the
Act of Krėva was concluded. The agreement provided for the marriage of the Grand Duke of Lithuania Jogaila to Jadwiga and his assumption of the Polish throne, in exchange for which the Grand Duke undertook to accept baptism (second baptism of Lithuania since Mindaugas) and
Christianize Lithuania. One of the conditions of the agreement was the return to the Kingdom of prisoners abducted by the Lithuanians and forcibly settled on the lands of the Grand Duchy. The alliance ended Lithuanian plundering expeditions into Polish lands, but did not end all wars. Among the last medieval Polish–Lithuanian was in 1431 – the and was a prelude to the
Lithuanian Civil War (1432–1438). Duke
Bolesław IV of Warsaw and another Masovian duke
Casimir II of Belz, taking advantage of the assassination of the Grand Duke of Lithuania
Sigismund Kęstutaitis (1440), reoccupied most of Podlachia in 1440. The Grand Duke of Lithuania
Casimir IV Jagiellon started a war with them over Podlachia in 1444. The Masovian dukes supported Casimir IV Jagiellon' rival for the throne of the Grand Duke of Lithuania,
Michael Žygimantaitis (who had married the daughter of
Siemowit IV), who had fled from Lithuania in 1444. This war ended in a compromise: Masovia returned Podlachia to the Grand Duchy of Lithuania, and the Grand Duchy of Lithuania paid compensation to Masovia. == Impact on the Polish economy and demographics ==