After 39 hearings over four years and allegations of anti-Muslim animus, a New Jersey township agreed Tuesday night to settle two federal lawsuits that accused officials of discriminating against an Islamic society seeking to build a mosque.
The Bernards Township planning board voted 6-1 at a hearing to settle with the Islamic Society of Basking Ridge and 5-2 with the Justice Department, township spokesman Michael P. Turner confirmed to NBC News.

The five-member township committee also approved settling both lawsuits in a 4-1 vote, he said.
Both the board and committee were named in the federal complaints.
The Islamic society went to court against the township last March after its application to build a 4,216-square-foot mosque was denied last January. The group alleged that in disapproving its bid, the planning board caved to anti-Muslim sentiment in the community and discriminated against the Islamic society based on religion.
RELATED: Mosque Battle Leaves Fissures in Small New Jersey Township
Bernards Township repeatedly denied those allegations, saying the decision was based solely on land-use considerations.
The terms of the settlement were not immediately known. Adeel Mangi, an attorney for the society, declined comment until the agreement becomes public.
Turner also declined comment.
“When the details of the settlement are available, I will have more to share,” he wrote in an email.
The Justice Department did not immediately respond to an emailed request for comment Tuesday night.

Lawsuits filed first by the society and then the Justice Department in November brought national media attention to this closely-knit community about 40 miles west of New York City.
While some Bernards Township residents supported the society’s plan to build a mosque, others fought against it. Some cited parking and traffic considerations as reasons for their opposition, suggesting that the society build elsewhere in town.
Others in interviews with NBC News in January said a mosque made them uncomfortable.
Those tensions were laid bare when community members packed public hearings and expressed their feelings to local government officials.
The Islamic society has said in court papers that it was targeted by bigots as the lengthy public hearing process played out.

Among other things, a flyer made the rounds in the community asking whether terrorist acts are "something they taught in your mosques and at home," and the society's mailbox was defaced with three-inch stickers to change its acronym from "ISBR" to "ISIS," according to the lawsuit.
During its investigation, documents turned over to federal authorities revealed some Bernards Township officials named in the society's lawsuit used their personal email accounts to allegedly make anti-Muslim statements.
But some residents have taken issue with how Bernards Township has been portrayed. They insist it is a place that welcomes all; a former mayor and current township committee member has also called the community warm and inclusive.
RELATED: Justice Department Sues New Jersey Township Over Years-Denied Mosque
On New Year's Eve, the Islamic society scored an important victory when a federal judge ruled the township discriminatorily enforced a parking ordinance by requiring that it have more spots than churches or synagogues.
That requirement, the society said, "laid the groundwork for each of the board's bases for denying [the society's] preliminary and final site plan approval."
But the township at the time criticized the judge’s decision, saying it “has major implications for municipal land use boards and their ability to determine the actual off-street parking needs of proposed projects without fear of alleged (religious land-use) violations."
With the nearest mosque a 25-minute car ride away, members of the Islamic Society of Basking Ridge pray at the Bernards Township Community Center, an olive green clapboard house with a separate garage that once served as the township administrator's residence.

It remains to be seen what will happen to the 1950s colonial home the society bought on Church Street in 2011. The group purchased the 4-acre property for $750,000, intending to raze the two-story house to build its mosque.
One Islamic Society of Basking Ridge member told NBC News the township’s decision to settle was an important vindication of their First Amendment rights.
“I think justice has prevailed and look forward to moving on together with the entire community of Basking Ridge,” Nadim Ahmed said.
Follow NBC Asian America on Facebook, Twitter, Instagram and Tumblr.