Ali Masjid was the scene of battles during the Anglo-Afghan wars. In 1842 during the First Anglo-Afghan War, the fort was garrisoned by the British. During the disastrous retreat from Kabul, a relief force under Colonel Charles Wild was attacked by Afghan troops of Akbar Khan at the entrance of the Khyber pass and forced to fall back. The fort garrison was also forced to evacuate Ali Masjid fort and fall back to Jamrud. During the Second Anglo-Afghan War, the Peshawar Valley Field Force under General Sir Samuel Browne, during the advance on Kabul in 1878, captured this fort which was held by the Afghans under Faiz Muhammad.