Afghanistan–Germany relations
Relations between Afghanistan and Germany reach back into the late 19th century and have historically been strong. 100 years of "friendship" was celebrated in 2016, with the Afghan President calling it a "historical relationship". History

Secret relations during British indirect colonial rule
The Treaty of Gandomak (26 or 30 May 1879) and the Treaty of the Durand Line overruled a prior agreement from 1893 concerning  of porous border between British India (now Pakistan) and Afghanistan. As a result of this treaty Britain gained full control of Afghan foreign policy from the king of Afghanistan. Germany, as a rival to Britain, was only able through secret missions and expeditions to reduce British influence in Afghanistan. Engineer Gebhard Fleischer, nicknamed The German James Bond in Kabul, was an engineer of the Krupp company, a German arms manufacturer. In 1893 he traveled to Kabul and privately met with the King Abdur Rahman Khan. Under the Kings orders he expanded the Afghan weapons companies Maschin Khana (House of machines) and Tupkhana (cannon house). It is not certain whether the government in British India knew of this journey. Later, in 1904, the Krupp engineers were mysteriously assassinated. Adamec writes:

Trade and Friendship treaty of 1916 
The relations between Germany and Afghanistan began before World War I. Relations between these two countries have historically been friendly. The second German-Afghan meeting between Habibullah Khan and a 23-member German delegation took place in 1915. The main intentions of this delegation was to weaken British influence in Afghanistan as part of the Niedermayer-Hentig expedition. However, during this expedition in 1916 a friendly trade-agreement occurred. The trade contracted concluded even though there were prior diplomatic relations between these countries. According to the Treaty of 24 January 1916 the German delegation to the Government of Afghanistan was promised 100,000 rifles and 300 guns. A friendship agreement was made  on 3 March 1926. With recognition of the ambassadors in both these countries. In 1926 the prior existing friendship and trade agreement of 24 January 1916 was ratified. Diplomatic relations and accreditation of consul 
The first Afghan delegation to Germany occurred in 1922 where the delegation traveled to Berlin for talks on diplomacy, trade and cultural relations. In response Germany sent Dr. Fritz Grobba to Afghanistan in 1932. For the first year he worked as Consul in Kabul, acting as the de facto German embassy, until 1926 then managing the ambassadors work in Kabul. The "Embassy" titled as the Diplomatic representation and the residence of the minister plenipotentiary was located in Kabul near the Gardens of Babur. The Afghan King, Amanullah Khan, visited Germany on 22 February 1928 where he met the President of the Weimar Republic, Paul von Hindenburg. 1930s and war period
Afghanistan established close ties with Germany, now under Adolf Hitler, in 1935 – forming important economic and technical connections, and seeking an alternative to its historical position as a contested territory between the USSR and Britain. Germany increased commercial transactions in Afghanistan during this period, with a weekly Berlin-Kabul air service established, and the Organisation Todt supervised major infrastructure projects in the country. Afghanistan resisted calls from Moscow and London to expel the Italian and German diplomatic corps at the beginning of the Second World War. During 1940 and 1941, there were plans initiated by Afghan economic minister Abdul Majid Zabuli for Afghanistan to join the Axis bloc in return for Germany providing additional military aid and access to the Karachi Port by taking land from British India. In addition, Zabuli spoke of "liberating" the 15 million strong ethnic Afghan population across the border. However following the Soviet Union's change of allegiance to the United Kingdom, and their joint invasion of Iran, Afghanistan was suddenly surrounded by the Allied forces. It eventually in October 1941 accepted their demand to expel Italians and Germans, although small diplomatic staff remained. Afghanistan was right on the demarcation line between the proposed division of Asia between Germany and Japan. At the end of the Second World War the German military donated its remaining arsenal to Afghanistan as a sign of good faith for its neutral stance during the war. Post-war
Afghanistan became one of the first countries to recognize the Federal Republic of Germany as the successor of the Third Reich. Pre-war cooperation was revived in 1950 (with West Germany), although full official relations did not start resume until December 1954. Ghulam Mohammad Farhad, who served as mayor of Kabul from 1948, hired and brought West German engineers and products for the Kabul Electric Company. The Afghan Cultural Office was opened in Munich in 1952. An agreement for economic and technical cooperation was signed between the Federal Republic and the Kingdom on January 31, 1958. Relations temporarily froze following the republican coup in Afghanistan, but was restored by 1976. Following the Soviet–Afghan War, the West German soldiers stationed in Afghanistan left the country. Qualified West German personnel and advisors left the country in 1980 followed by teaching staff in 1984. Meanwhile, East Germany supported the Soviet role in the country and assisted the Afghan government. Afghanistan and East Germany did not have many links since the latter was recognized in 1973, but this all changed during the Afghan communist regime. Cultural and economic agreements were made, and both countries' media agencies cooperated. The basis was formed following a visit by Afghan leader, Babrak Karmal, to East Germany, after which a Treaty of Friendship and Cooperation was signed on May 21, 1982. Their cooperation had a particular focus on the education sector. In 1985, total East German solidarity donations to Afghans was over 200 million marks, most of which came from the Free German Trade Union Federation. After German reunification

The German Armed Forces were part of the ISAF mission in Afghanistan from December 2001. Germany hosted the Bonn Conference, which chose Hamid Karzai as Afghanistan's interim leader in 2001. Currently Germany is engaged in a security mission with its military and reconstruction efforts in the northern areas of Afghanistan, and has been one of the principal donors to Afghanistan. On 23 December 2021, German Foreign Minister Annalena Baerbock warned that Afghanistan is "heading into the worst humanitarian catastrophe of our time," with major economic sectors collapsing and more than 24 million people in need of humanitarian assistance. She promised to speed up the evacuation of more than 15,000 vulnerable Afghans, including local Afghan staff who worked for Germany and their family members. 