After Algirdas's death in 1377, his son Jogaila became the new Grand Duke of Lithuania, but tensions soon arose with his uncle Kęstutis, who had co-ruled parts of the duchy. At this time, Lithuania faced growing pressure from the Teutonic Knights, and Jogaila was more concerned with preserving Lithuania's Ruthenian territories than continuing Kęstutis's longstanding defense of Samogitia against the Knights. The Teutonic Order exploited these differences between Jogaila and Kęstutis, securing a temporary armistice with Kęstutis in 1379.
In 1380, Jogaila secretly negotiated the Treaty of Dovydiškės with the Teutonic Order, agreeing to peace in exchange for support, directly betraying Kęstutis. Feeling abandoned and betrayed, Kęstutis took action in 1381 while Jogaila was distracted with a rebellion in Polotsk. Kęstutis seized Vilnius and removed Jogaila from power, sparking a civil war between the two factions. Kęstutis mounted two raids against Teutonic strongholds in 1382, but while absent from Vilnius, Jogaila regrouped, retook the city, and captured Kęstutis, who later died in Jogaila's custody under suspicious circumstances. Kęstutis's son, Vytautas, managed to escape.
Jogaila’s position remained weak, and in 1382, he signed the Treaty of Dubysa with the Teutonic Order, promising to convert to Catholicism and cede half of Samogitia to the Knights. Meanwhile, Vytautas fled to Prussia, seeking the Order’s support to claim the Duchy of Trakai, which he considered his inheritance. However, when the Order and Vytautas failed to achieve their goals through their 1383 invasion of Lithuania, Vytautas reconciled with Jogaila. In 1384, Vytautas switched sides, receiving control over Grodno, Podlasie, and Brest from Jogaila. Vytautas even destroyed Teutonic strongholds entrusted to him, and together, the two cousins launched a joint campaign against the Teutonic Knights.
By the mid-1380s, it was clear that Lithuania needed to align with European Christendom to ensure its survival. The Teutonic Knights, seeking to unify their Prussian and Livonian territories, hoped to conquer Samogitia and all of Lithuania, just as they had done with other Baltic tribes. Between 1345 and 1382, the Knights launched 96 raids into Lithuania, while Lithuanian forces could only respond with 42 retaliatory campaigns. To the east, Lithuania’s vast Ruthenian territories were under increasing threat from the expanding ambitions of Moscow and local rulers seeking independence, forcing Lithuania to navigate both external and internal threats in the struggle for survival.