Present-day Hungary became part of the Roman Empire in the first century. In the fourth century, the Goths ruled the area. They were eclipsed by the Huns in the fifth century. Then, the Avarians overtook the region in the seventh and eight centuries. Magyar tribes from Eastern Europe entered the area in 895 and establish the state of Hungary. In 1526, Hungary was invaded by the Ottoman Empire. The northern and eastern parts of Hungary avoided Ottoman rule by becoming part of the Austrian Empire. Gradually the Ottomans were driven out of Hungary. In 1849 Hungary was formally annexed to Austria. In 1867 Austria was restyled into the Austro-Hungarian Monarchy, of with the Kingdom of Hungary was one of the two constituent parts.
After the defeat of Austria-Hungary in World War I, Hungary became independent. In 1919 communist seized power and establish the Hungarian People's Republic. Later that year a counter revolution succeeded and Hungary became a dictatorship. In World War II Hungary allied itself with Germany. At the end of the war following an unsuccessful attempt to switch sides in 1944 Hungary fell under German military occupation.
In 1945, Hungary was invaded by the Soviet Union and in elections tainted by fraud in 1947 the communist gained control of the government. In 1956, pressure for change reached a climax when security forces fired on Budapest students marching in support of Poland's confrontation with the Soviet Union. The ensuing battle quickly grew into a massive popular uprising that was put down by Soviet troops. In 1989 the communist gave up power voluntarily and Hungary became a parliamentary democratic republic. Hungary joined the European Union in 2004.