Slavic ancestors of Slovenians came from eastern parts of Europe and inhabited territory north of present Slovenian territory in the 6th century AD. They established a state called Caranthania ( Karantanija in Slovene), which was an early example of parliamentary democracy in Europe. The ruler ( knez in Slovene) was elected by popular vote. The Caranthanians were later defeated by Bavarians and Franks who subjugated them. They were christianized but they preserved many rituals of their pagan religion, and above all they preserved their native language.
The Slovene lands were part of the Holy Roman Empire and Austria under Habsburg dynasty until 1918 when the Slovenes joined the Serbs and Croats in forming a new south-Slavic state ruled by Serbian Karadjordjevic dynasty called the Kingdom of Serbs, Croats and Slovenians ("Kraljevina Srbov, Hrvatov in Slovencev" in Slovene), renamed Yugoslavia in 1929. In WWII, Slovenia was invaded and occupied by Germans, Italians and Hungarians, leading to a parallel civil war between pro-communist liberation forces (Partizani) and axis-sponsored anti-communist reactionary factions ("Belogardisti" and Domobranci). The victory of the Allies and consequently the Partizans resulted in a violent mass exodus of those who had fought with with the occupying forces, including most of the native German and Italian minorities.
After World War II, Slovenia became a republic in the reestablished Yugoslavia, which although Communist, distanced itself from the Soviet bloc and small territorial gains were made from Italy. Dissatisfied with the exercise of power in Belgrade, the Slovenes succeeded in establishing their independence in 1991 with minimal bloodshed. In 2004, Slovenia joined the European Union and NATO. Most recently, Slovenia adopted the euro in 2007, completing a quick and efficient accession to Europe and the EU.