Aibak later rose to the important position of "amir-i akhur", the officer of the royal stables. During the Ghurid conflicts with the Khwarazmian ruler Sultan Shah, Aibak was responsible for the general maintenance of the horses, as well as their fodder and equipment. One day, while foraging for horse fodder, he was captured by Sultan Shah's scouts, and was detained in an iron cage. After the Ghurids defeated Sultan Shah, Mu'izz ad-Din saw him in the cage, and was deeply touched by his desperate condition. After he was released, the Sultan greatly favoured him. No information is available about Aibak's subsequent assignments until the First Battle of Tarain fought in India, in 1191-1192.