Poland, with support of the papacy, was able to increase its ties with the Grand Duchy, by signing the Union of Vilnius and Radom in 1401. The same year Samogitians rebelled against the Knights. The rebels burnt several Teutonic castles. The Knights retaliated by raiding Kaunas and Grodno. In 1402 the Order allied with Lithuanian duke Švitrigaila, brother of Władysław II Jagiełło, who promised to follow the Treaty of Salynas and cede Samogitia to the Knights.
When neither side could achieve decisive victory and Vytautas the Great wanted to direct his attention to a war against Yury of Smolensk, the negotiations started in summer 1403. The final treaty was signed in Raciążek and addressed some of the territories disputed between Poland, Lithuania and the Order: the Dobrzyń Land was to return to Poland for a fee, Samogitia was to remain with the Order, and the discussion regarding the Gdańsk (Danzig) region was inconclusive. Švitrigaila was allowed to return to Podolia.