The Treaty of Gandomak (26 or 30 May 1879) and the Treaty of the Durand Line overruled a prior agreement from 1893 concerning 2,640 kilometres (1,640 mi) of porous border between India (now between 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:
The first German known to reside in Kabul was Gottlieb Fleischer, an employee of Krupp Stellworks of Essen, Germany, who was contracted by Amir Abdul Rahman in 1898 to start manufacture of ammunitions and arms in the newly constructed factory (mashin Khana) at Kabul. He was killed in November 1904 near the border while traveling to India.
Trade and friendship treaty of 1916
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. 
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 personal 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.
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.
- Ludwig W. Adamec: Historical Dictionary of Afghanistan, 4th ed., 2012, ISBN 978-8170493112
- Ludwig W. Adamec: Afghanistan's Foreign Affairs to the Mid-Twentieth Century: Relations with the USSR, Germany, and Britain. Tucson: University of Arizona Press, 1974, ISBN 978-0816504596
- https://af.boell.org/2015/08/30/century-afghan-german-friendship[permanent dead link]
- Tom Appleton (9 February 2003). "Ein deutscher James Bond in Kabul".
- Germany-Afghanistan Relations in :Ludwig W. Adamec: Historical Dictionary of Afghanistan, 4th ed., 2012, p. 162, ISBN 978-8170493112.
- Necipoglu, Gulru (2002). Muqarnas: An Annual on the Visual Culture of the Islamic World. BRILL. ISBN 90-04-12593-0.
- Adamec, Ibid.
- "European Business Network".
- Text in League of Nations Treaty Series, vol. 62, pp. 116–125.
- Clements, Frank A.: Conflict in Afghanistan: A historical encyclopedia, 2003, p.7
- Eur (2002). The Far East and Australasia 2003. ISBN 9781857431339.
- Tom Lansford. A bitter harvest: US foreign policy and Afghanistan. Ashgate Publishing, Ltd., 2003 ISBN 0-7546-3615-1, ISBN 978-0-7546-3615-1. Pg 2
- Gerhard Schreiber, Bernd Stegemann, Detlef Vogel: The Mediterranean, South-east Europe, and North Africa, 1939–1941: From Italy's Declaration of Non-belligerence to the Entry of the United States Into the War, Clarendon Press, 1995, pp. 163–164.
- Hyman, Anthony (27 July 2016). Afghanistan under Soviet Domination, 1964–91. ISBN 9781349219483.
- Zeter, Kerstin (17 October 2014). "Rückblick: Die deutsch-afghanischen Beziehungen". Planet Wissen (in German). Retrieved 30 December 2014.