The Durrani dynasty diminished in the early 19th century when Afghanistan was fighting defensive wars with Persia on one side and British India on the other side. The Barakzai dynasty took over control of the kingdom but lost many of Afghanistan's territories by the end of the 19th century. It became to what is now Afghanistan after the Anglo-Afghan Treaty of 1919 when the state became officially recognized by all the major countries in the world.