A US city finally gave approval for the construction of a mosque in the state of New Jersey, ending a saga that started last year when the local government rejected the effort and a group of Muslims sued in response.

The approval late on Monday came after the two-year effort to convert an abandoned warehouse into a mosque and Islamic community centre in Bayonne, a working-class city across the harbour from New York City.

According to the lawsuit, the effort for the mosque was met by virulent attacks against the Muslim religion and was then unfairly voted down by the city's zoning board.

"We are very pleased to have received a unanimous approval from the zoning board and look forward to welcoming Bayonne residents of all faiths to the city's first mosque," said Adeel Mangi, a lawyer for the Muslim group, told The Jersey Journal.

Attacks against the mosque effort included flyers calling for boycotts of Muslim-owned businesses with references to the September 11 attacks, and anti-Muslim graffiti on the walls of the church the Muslim community rented for prayer services.

Signs saying "Save Bayonne" and "Stop the mosque" were displayed around the town.

At one zoning board hearing, a person argued the mosque should be denied because people would become "radicalised" and kill others, the lawsuit said.

Before the zoning board unanimously approved the mosque on Monday, opponents called again for its rejection. "I do not believe our city should bend to the threat of a lawsuit," said Joseph Basile, a local pastor.

City officials noted a lengthy legal battle could have cost Bayonne millions of dollars.