BAYONNE, N.J. — A New Jersey city that denied a Muslim group’s bid to build a mosque last summer has reached a settlement with the group that will allow the project to proceed.

The settlement made public Wednesday calls for Bayonne to pay the group $400,000 and have the project go before the city’s zoning board for another vote. City officials noted that a lengthy legal battle could have cost Bayonne millions of dollars.

The Bayonne Muslims had filed a federal lawsuit against the city in May, arguing that their two-year effort to convert an abandoned warehouse into a mosque and community center was met by virulent attacks against their religion and was then unfairly voted down by a zoning board.

The group said the attacks included flyers calling for boycotts of Muslim-owned businesses with references to the Sept. 11 attacks and anti-Muslim graffiti on the walls of the church they rented for prayer services. Signs saying “Save Bayonne” and “Stop the mosque” were displayed around the town.

The zoning board in the working-class city across the harbor from New York City voted 4-3 in favor of the mosque proposal in March, but it needed a minimum of five votes to pass. Those who voted against it cited parking and traffic concerns, although the Bayonne Muslims argued that the building would be located in an uncongested part of the city with ample parking.

Shortly after the board’s vote, federal law enforcement officials said they were investigating the city’s decision. That came a day after the U.S. Department of Justice announced a $3.25 million settlement between a different New Jersey town and an Islamic group — a deal that requires the town to allow a mosque to be built after a similar zoning dispute.

“We are so grateful for the support of so many of our fellow Bayonne residents through this long struggle and we commend the City of Bayonne for moving now to correct the wrong that was done to Bayonne’s Muslims,” Abdul Hamid Butt, the organization’s president, told The Jersey Journal. “We look forward to welcoming Bayonne residents of all faiths to the city’s first mosque.”