Nepali historians believe that the first Muslims settled in Kathmandu during King Ratna Malla's reign in the late 15th century. Kashmiri traders were probably the first Muslims to arrive, followed by Afghans, Persians and even Iraqis. The Raqi Bajar in Indra Chok gets its name from the Iraqi merchants.
The chaubise rajas of west Nepal also employed Afghan and Indian Muslims to train Nepali soldiers to use firearms and ammunition. Ratna Malla's envoy to Lhasa invited Kashmiri Muslims to Kathmandu in an attempt to profit from the rugs, carpets, shawls and woollen goods they traded between Kashmir, Ladakh and Lhasa. The first batch of Muslims came with a Kashmiri saint who built the first mosque, Kashmiri Taquia, in 1524, writes Shamima Siddika in her book Muslims of Nepal.
Influenced by the system of Mughal courts in Delhi, the Mallas also invited Indian Muslims to work as courtiers and counsellors-leading to rivalry with Newar nobles of the Malla courts. While the Muslim courtiers did not last long and returned to India, other Muslims stayed on. The Mallas also got Indian Muslims from the Mughal Empire to join their courts as musicians and specialists on perfumes and ornaments. Historian Baburam Acharya believes they were also there to protect King Ratna Malla from rebellious relatives and senior court officials.
Following Nepal's unification, King Prithbi Narayan Shah also encouraged Muslim traders to settle down with their families. Besides trade, the Muslims from Afghanistan and India were experts in manufacturing guns, cartridges and canons, while others were useful in international diplomacy because of their knowledge of Persian and Arabic.
Many Muslims, especially Kashmiri traders, are said to have fled to India during the economic blockade that Prithbi Narayan Shah imposed on the Valley. Fearing persecution from a Hindu king due to their religion and their ties with the Mallas, the traders left despite assurances that they would come to no harm. By 1774, only a handful of Kashmiri merchants remained. Even so, Kashmiri traders proved to be a great help during the unification process. Historians say that Prithbi Narayan Shah employed them as spies and informants as they had personal contacts with the Malla rulers. After his victory, he gave them permission to build a mosque, now near Tri-Chandra Campus (see pic, left, taken in 1925 from top of Ghanta Ghar).
During Jang Bahadur Rana's regime, a large number of Muslims migrated to the tarai from India fleeing persecution by the British army during the Sepoy Mutiny in 1857. These refugees settled in the tarai, selling leather goods or working as agricultural labourers. A senior courtier to Delhi Emperor Bahadur Shah Zafar also fled to Kathmandu. Later, he renovated the Jama Masjid and was buried there. During the Sepoy Mutiny, Begum Hazrat, wife of Nawab Wajid Ali Shah of Lucknow also escaped to Kathmandu via Nepalganj and was allowed by Jang Bahadur to take refuge in Nepal. She settled down at the Thapathali Durbar, and later died in Kathmandu and was also buried at the Nepali mosque.