Until the end of the First World War, Hungary was part of the dual monarchy of the Austro-Hungarian empire, but it became the independent Kingdom of Hungary.
From Wikipedia:
The new borders set in 1920 by the Treaty of Trianon ceded 72% of the historically Hungarian territory of the Kingdom of Hungary to the neighbouring states. The beneficiaries were Romania, the newly formed states of Czechoslovakia, and the Kingdom of Serbs, Croats and Slovenes (later known as Yugoslavia).
Today, large numbers of indigenous Hungarians are found in Romania, Slovakia, Serbia and Ukraine, and to a lesser extent also in Austria, Slovenia and Croatia.
During World War 2, Hungary fought on the side of the Axis, before switching to the Allied side in 1944. It was occupied by Soviet troops after the war, who pressured the country to become a republic and allow the communists to take over the government. The Hungarians rebelled against communist rule in 1956, but Hungary was invaded by Soviet troops and other forces of the Warsaw pact, who brutally put down the rebellion.
Under the influence of Soviet president Mikhail Gorbachev, the Hungarian communist government began liberalising its regime in the late 1980s.
From Wikipedia:
On 2 May 1989, the first visible cracks in the Iron Curtain appeared when Hungary began dismantling its 150 mile long border fence with Austria. This increasingly destabilized the German Democratic Republic and Czechoslovakia over the summer and autumn, as thousands of their citizens illegally crossed over to the West through the Hungarian-Austrian border. The resulting exodus shook East Germany and hastened the fall of the Berlin Wall.
On 1 June 1989 the Communist Party admitted that former Prime Minister Imre Nagy, hanged for treason for his role in the 1956 Hungarian uprising, was executed illegally after a show trial. On 16 June 1989 Nagy was given a solemn funeral on Budapest's largest square, followed by a hero's burial.
On 23 October, Mátyás Szűrös declared Hungary a republic. The state party agreed to give up its monopoly on power, paving the way for free elections in March 1990. The party's name was changed from the Hungarian Socialist Workers' Party to simply the Hungarian Socialist Party, but the 1990 election was won by the centre-right Hungarian Democratic Forum (MDF). As Gorbachev looked on, Hungary changed political systems with scarcely a murmur and the last Soviet troops left Hungary in June 1991.