Angel Ros, the socialist mayor of Lleida, in the northeastern region of Catalonia, complained that the mosque was too full and closed it on Wednesday until further notice.
The building, a former garage used to service trucks, was often filled with crowds exceeding a thousand people, the council said, when the authorised limit for the venue is 240.
A new mosque is under construction on the outskirts of the town but work had been stalled because of a lack of financing during the economic crisis.
"The municipality has no obligation to provide places of worship," Mr Ros said in response to complaints from the town's Muslim population over the closure. "Those that wish can pray at home, as I do," he added.