King of Bavaria was a title held by the hereditary Wittelsbach rulers of Bavaria in the state known as the Kingdom of Bavaria from 1805 till 1918, when the kingdom was abolished. It was the second kingdom, almost a thousand years after the short-lived Carolingian kingdom of Bavaria.
Maximilian's successors resisted German nationalism, and Bavaria became the protector of smaller states whose leaders felt threatened by Prussia or Austria in the German Confederation. Religious ties linked the state more to Austria until their defeat in the Austro-Prussian War. King Ludwig II signed an alliance with Prussia on 22 August1866, effectively relinquishing Bavarian independence.
With the treaty of 23 November1870 Bavaria was integrated into the new German Empire, but permitted a relatively large degree of self-determination. The Kings of Bavaria maintained their titles, and maintained separate diplomatic and military corps. When the German Empire was abolished in November 1918 after the end of World War I, the last king of Bavaria, Ludwig III, was deposed.