The Ottomans were driven out of Eger in 1687 by an Austrian Imperial Army led by Charles of Lorraine. The mosque was converted into a Catholic church dedicated to St. Joseph after the Turkish rule. In 1726, the mosque premises was transformed into the Brothers of Mercy Hospital.