At the end of 1918 Soviet Russia invaded Lithuania with massive forces, and the Lithuanian Army withdrew from Vilnius to the center of the country in order to form a defense line. The German Army withdrew together with the Lithuanian government. The Self-Defence of Lithuania, which was affiliated with the Second Polish Republic, briefly controlled the city and unsuccessfully tried protecting it against the invading Soviet forces. Vilnius changed hands again during the Polish–Soviet War and the Lithuanian Wars of Independence: it was taken by the Polish Army, only to fall to Soviet forces again. Shortly after the Red Army's defeat at the 1920 Battle of Warsaw, in order to delay the Polish advance, the Soviet government ceded the city to Lithuania after the signing the Soviet–Lithuanian Peace Treaty on 12 July 1920.