Struggle for power
Vytautas' uncle Algirdas had been Grand Duke of Lithuania until his death in 1377. Algirdas and Vytautas' father Kęstutis had practically ruled jointly, with Algirdas governing the east and Kęstutis the west, primarily responsible for defense against the Teutonic Order. Algirdas was succeeded by his son Jogaila, and a struggle for power ensued. In 1380, Jogaila signed the secret Treaty of Dovydiškės with the Teutonic Order against Kęstutis. When Kęstutis discovered this in 1381, he seized Vilnius, imprisoned Jogaila, and made himself Grand Duke. However, Jogaila escaped and raised an army against Kęstutis. The two sides confronted each other but never engaged in battle. Kęstutis was ready to negotiate, but he and Vytautas were arrested and transported to Kreva Castle. One week later, Kęstutis was found dead. Whether he died of natural causes or was murdered is still a matter of debate.
In 1382, Vytautas escaped from Kreva. He sought help from the Teutonic Order, who were negotiating with Jogaila at the time. Jogaila and the Order agreed to the Treaty of Dubysa, by which Jogaila promised to accept Christianity, become an ally of the Order, and give the Order part of Samogitia up to the Dubysa River. However, the treaty was never ratified. In summer 1383, the war between Jogaila and the Order resumed. Vytautas was baptised as a Catholic, receiving the name of Wigand (Lithuanian: Vygandas). Vytautas participated in several raids against Jogaila. In January 1384, Vytautas promised to cede part of Samogitia to the Teutonic Order, up to the Nevėžis River in return for recognition as Grand Duke of Lithuania. However, in July of the same year, Vytautas broke with the Order and reconciled with Jogaila. He then burned three important Teutonic castles, and regained all Kęstutis' lands, except for Trakai.
Poland and Lithuania, 1386–1434
In 1385, Jogaila concluded the Union of Krewo with Poland, under which he married Jadwiga of Poland and became King of Poland as Władysław II Jagiełło. Vytautas participated in the Union and in 1386 was re-baptised as a Catholic, receiving the name Alexander.
Jogaila left his brother Skirgaila as regent in Lithuania. However, Skirgaila was unpopular with the people and Vytautas saw an opportunity to become Grand Duke. In 1389, he attacked Vilnius but failed. In early 1390, Vytautas again allied with the Teutonic Order. Vytautas had to confirm his agreement of 1384, and cede Samogitia to the Order. His army now invaded Lithuania. Also, to gain more influence, Vytautas married his only daughter Sophia to Vasili I of Russia in 1391.
The Polish nobles were unhappy that their new king spent too much time on Lithuanian affairs. It was clear that the war could continue for years and would not bring any benefit to Poland. In 1392, Jogaila sent Henry of Masovia with an offer to make Vytautas regent instead of Skirgaila. Vytautas accepted and again broke with the Order. He burned three Teutonic castles and returned to Vilnius. Jogaila and Vytautas signed the Astrava Treaty in which Vytautas recovered all Kęstutis' lands, including Trakai, and was given more. Vytautas would rule Lithuania in the name of Jogaila. After Vytautas' death, all his lands and powers would revert to Jogaila.