The title of Chancellor (called "Bundeskanzler" in Germany and Austria) has its origin in the early medieval kingdom of East Francia. East Francia was one of the kindoms of Franks and Frank rulers often elected a special official that oversaw the work of notaries. The offices of notaries were the "loca credibilia" places that were in charge of state records, recording and updating laws, diplomatic edicts, privileges, rights and obligations of nobles, cities and clergy and as such they were of great importance for a large Kingdom like East Francia. The office of archchancellor was therefore the most important office in the medieval royal administration. Historically, it was held by archbishop of Mainz. With the formation of the Holy Roman Empire, archchancellor of East Francia became archchancellor of Germany (similar office was introduced in the Kingdom of Italy and was held by archbishop of Cologne) and the title remained in usefar into the 19th century, held by archbishops of Mainz although at some moments it was nothing more than a honorary title. The last archchancellor was Karl Theodor Anton Maria von Dalberg whose office was abolished in 1806 with the dissolution of the Holy Roman Empire.
In the late 19th century, with the emergence of pangermanism, the impulse to create new German empire around the crown of Prussia mostly came from Otto von Bismarck, uncouth rural noble whose ambition and education in foreign languages secured him the post of the Foreign minister of Prussia.Since Bismarck, as a romantic and militaristic polititian held little regard for democracy and parliamentarism the apsolutist character of the new nation was to be based upon the historical traditions of Holy Roman Empire, the institution that German nationalist have mythologized as "The first Reich". Calling upon the HRE was also important to delegitimize the Austrian Habsburgs as a potential political body around which the German lands are to be unified, since Bismarck, a traditional protestant despized catholic Austrian throne.Thus, at first the North German Confederatio was formed in 1867 and Bismarck took the position of the Chancellor or head of government of the Confederation. Government of the Confederation held little but an administrative role, and Chancellor, responsible only to the Presiden of COnfederation, title that was to be held exclusively by Prussian Kings of the house Hohenzollern. The office of Chancellor was carried as Reichskanzelar into the German Empire and had survived in all incarnations of the German state.
Sources: Dreadnought: Britain, Germany, and the Coming of the Great War by Robert K. Masie for the formation of the government of the German Empire, and an old (and somewhat biased, but servicable) book by H. Reinecke "Der alte Reichstag and der neue Bundesrat" written in 1906 for the ideological continuity of German political system with the institutions of the HRE