Dedicated to Lord Vishnu, the Hindu temple, built by Beni Madhur Rao Scindia, a Maratha chieftain, was demolished when the emperor Aurangzeb had captured Banaras and razed the temple. Aurangzeb then built a mosque over the ruins of the temple in 1669 and named it as Alamagir Mosque in the name of his own honorific title Alamgir, which he had adopted after becoming the emperor of the Mughal empire.