In the end of October 1918 Hungary left the state union with Austria. The new Prime Minister Mihály Károlyi proclaimed the democratic Republic of Hungary on 16 November 1918. Through territorial secessions, Hungary lost about two thirds of its territory to neighbouring states. These territorial losses put a heavy burden on the young government and soon led to its collapse in favour of a short-lived Communist-dominated Soviet Republic under the leadership of Béla Kuns. That regime entered a war against Romania but was defeated and in November 1919 Admiral Miklós Horthy came to power. He remained Hungarian head of state until 1944.
From 1933 onwards, Hungary moved closer to National Socialist Germany. With its support, it regained some of the territories lost in 1918/19 before and during the World War II. In return, Hungary entered the war as an ally of Germany in 1940 but wanted to withdraw from it again in early 1944 when the tide was turning. As a result, German troops occupied the country and the deportation of Hungarian Jews began. In the summer of 1944, the Red Army reached Hungarian territory and completely occupied the country by April 1944. Hungary remained under Soviet influence after the war.
The Hungarian Communist Party became only the third strongest force in free parliamentary elections in November 1944. Yet, the Soviet Union forced the other parties to include the Communist Party into their government. Subsequently, they gradually expanded their political influence. In 1948 the Social Democratic Party of Hungary was forced into a union with the Communist Party and in August 1949 a constitution based on the Soviet model was adopted. Stalinist politics led to a popular uprising in October 1956, as a result of which the reformist Imre Nagy was appointed Prime Minister. Until mid-November 1956, the Soviet army crushed the uprising in a bloody manner and put a Soviet-friendly politician, János Kádár, as new Prime Minister into power. He remained in office until 1988,
His successor Miklós Németh reformed the system in the end of 1988. On 23 October 1989 - the anniversary of the Hungarian National Uprising - the Republic of Hungary was proclaimed. A modified version of the socialist constitution of 1949 was established. The constitution was, among other sources, inspired by the German Constitution. In March 1990 Hungary held its first free parliamentary elections since 1947.
The Soviet occupation of Hungary lasted over 47 years and the last Soviet soldiers left the country on 16 June 1991.