The origins of modern-day Austria date back to the time of the Habsburg dynasty when the vast majority of the country was a part of the Holy Roman Empire. From the time of the Reformation, many Northern German princes, resenting the authority of the Emperor, used Protestantism as a flag of rebellion. The Thirty Years War, the influence of the Kingdom of Sweden and Kingdom of France, the rise of the Kingdom of Prussia, and the Napoleonic invasions all weakened the power of the Emperor in the North of Germany, but in the South, and in non-German areas of the Empire, the Emperor and Catholicism maintained control. During the 17th and 18th centuries, Austria was able to retain its position as one of the great powers of Europe and, in response to the coronation of Napoleon as the Emperor of the French, the Austrian Empire was officially proclaimed in 1804. Following Napoleon's defeat, Prussia emerged as Austria's chief competitor for rule of a larger Germany. Austria's defeat by Prussia at the Battle of Königgrätz, during the Austro-Prussian War of 1866 cleared the way for Prussia to assert control over the rest of Germany. In 1867, the empire was reformed into Austria-Hungary. After the defeat of France in the 1870 Franco-Prussian War, Austria was left out of the formation of a new German Empire, although in the following decades its politics, and its foreign policy, increasingly converged with those of the Prussian-led Empire. During the 1914 July Crisis that followed the assassination of Archduke Franz Ferdinand of Austria, Germany guided Austria in issuing the ultimatum to Serbia that led to the declaration of World War I.
After the collapse of the Habsburg (Austro-Hungarian) Empire in 1918 at the end of World War I, Austria adopted and used the name the Republic of German-Austria (Deutsch-Österreich, later Österreich) in an attempt for union with Germany, but was forbidden due to the Treaty of Saint-Germain-en-Laye (1919). The First Austrian Republic was established in 1919. In the 1938 Anschluss, Austria was occupied and annexed by Nazi Germany. This lasted until the end of World War II in 1945, after which Germany was occupied by the Allies and Austria's former democratic constitution was restored. In 1955, the Austrian State Treaty re-established Austria as a sovereign state, ending the occupation. In the same year, the Austrian Parliament created the Declaration of Neutrality which declared that the Second Austrian Republic would become permanently neutral.