He was attached to the British Egyptian army and, as commanding officer of the 12th Sudanese Battalion, he fought in the Sudan at the Battles of Atbara and the Omdurman in 1898, for which he was awarded the Distinguished Service Order. In January 1896, he received a letter from Herbert Kitchener, who wrote that he wanted him to serve under his command in Egypt, which served as a measure of Townshend's fame that a general would ask a mere captain not even under his command to take charge of one of his battalions. During battles with the Islamic fundamentalist "Ansar" of the Sudan from 1896 to 1899, culminating in Omdurman, he was promoted by Kitchener to major and was mentioned in dispatches for outstanding bravery for the fourth and fifth time. Commanding the 12th Sudanese Battalion revealed the paradoxical attitudes held by him to non-white peoples, contrasting his care for his men and great pride in their achievements yet assuming the automatic superiority of the British over anyone not white, and he did not hesitate to blame failures of his men on their skin color. On 7 March 1896, he described the men of the Battalion as: "I am very pleased with the physique of the men. They are fine strapping blacks, mostly tall. I felt quite small inspecting them. … I felt I had a stroke of luck in getting command of this regiment." On 5 June 1896, he first encountered the "Ansar", whom the British incorrectly called the "Dervishes" at the Battle of Ferkeh. Kitchener defeated the "Ansar" and Townshend wrote about the battle in his diary: