The Jama Masjid was built by Hassan Mahdi, the prime minister of Sultan Mahmud Ghaznavi in 1019. It was considered to be the first mosque in North India which was later restored by the Mughal Emperor Humayun. The Gazette for this region says some Buddhist statuettes were found nearby during digging sometime in 1901.