The Raebareli (UP) born Syed Ahmad Barelvi had declared Jihad against Bhatti Jatsikh ruler Maharaja Ranjit Singh just because he happened to be non-Muslim ruler. The Syed thought he would replace Maharaja first and then tackle British. He found no support in Punjab and went to Frontier (then Peshawar province) and started his campaign there. The Pathans from all around began to flock under the green flag of the Syed. In two months, their number grew to 50,000. The Barakzai chiefs of Peshawar with an army of 20,000 strong and 8 pieces of cannon joined them.
A considerable Sikh force under Sher e Punjab cousins Sardar Budh Singh Sandhanwalia of Raja Sansi was concentrated at the small village of Pirpai near Saidu (now in Swat district) situated 32 km south of Peshawar. Budh Singh was joined by Atariwala sardars. The Sikh army numbered about 10,000 with 12 cannons. Budh Singh by tact and diplomacy won over the Barakzai chief of Peshawar to remain neutral.
The Sikhs lay in their trenches under heavy assaults of the Ghazis for a few days. When their supplies were about to be exhausted, Budh Singh led the attack. The Sikh guns created havoc among the enemy. They took to flight. About 6,000 Mujahidin were killed and wounded. Murray says that the Sikh horsemen gave the fleeing Ghazis a hot pursuit. The Syed fled into the Swat hills. Ranjit Singh sent dresses of honour to Sardar Budh Singh Sandhanwalia of Raja Sansi and other commanders for their victory.
In subsequent years Barelvi fought with Pathans as well (as many of them didn’t agreed to his interpretation of Shariah). He defeated and killed Khadi Khan in battle of Hund in 1829 and later that year defeated Yar Mohd Khan, chief of Peshawar in battle of Zaidah. Yar Mohd Khan was seriously wounded and died after few days. Next year 1830, Barelvi defeated Sultan Mohd Khan (younger brother of Yar Mohd Khan), the chief of Peshawar. These brothers paid tribute to Maharaja at Lahore hence stage was set for the final battle between Sikhs and Barelvi.
- History of the Sikhs Vol 5 The Sikh Lion of Lahore – Maharaja Ranjit Singh by HR Gupta