WARREN, Maine — A settlement was reached Thursday in a contentious lawsuit by a company that tried unsuccessfully to open a methadone clinic in town.

The insurance company for the town of Warren will pay CRC Health Group Inc. $495,000 to drop its lawsuit, Town Manager Elaine Clark said Thursday after an all-day mediation session. The town will not have to pay anything since there is no deductible in the town’s insurance policy with Darwin National Assurance Co., she said.

The settlement was reached less than two months after a federal magistrate concluded in his recommended ruling that Warren’s ordinance regulating methadone clinics was discriminatory and violated the federal Americans With Disabilities Act. U.S. District Court Magistrate Judge John Nivison approved the agreement Thursday after the session.

CRC filed the federal lawsuit when the town imposed a moratorium on methadone clinics in order to develop the new ordinance. Then, i n August 2011, residents adopted an ordinance that restricted the location of methadone clinics and established 500-foot setbacks from homes, schools, churches, playgrounds, day care centers and libraries.

“The company is very pleased with the outcome of this matter,” CRC’s general counsel Pam Burke said in a statement issued Thursday evening. “Moratoriums and other ordinances that are clearly designed to keep those in recovery out are not legal and there are financial consequences for such discriminatory behavior.

“We would have preferred to have opened a clinic to serve those patients in need,” Burke said. “CRC has an obligation to stand up for those who need treatment to ensure that they have a place to get treatment.”

CRC Health Group, which waged a multiyear battle to open a methadone clinic in Warren, had estimated that its lost income could have been as great as $4.4 million.

“The town is very pleased to put this behind it and to move forward,” said Town Manager Clark.

As part of the settlement, the lawsuit is dropped and cannot be refiled, she said. The town also dropped its opposition to the magistrate’s recommended ruling.

Attorney Walter McKee, who also represented CRC, said this was an important decision.

“The magistrate judge found that the town unquestionably discriminated against CRC in passing the original moratorium,” McKee said.

Attorney James Green, another CRC attorney, said that the judge’s ruling will be a precedent that will be followed in federal courts across the country.

CRC and the town had appeared to reach a settlement in September 2011 when the town agreed to pay the company $1 and the town’s insurance company would pay the remaining $320,000 in damages in exchange for agreeing to review the project and adopt it if it met the law.

The Warren Planning Board approved the project in June 2012 but neighbors to the proposed clinic at the intersection of Route 1 and Short Street filed an appeal before the town’s aoning board of appeals. The Warren Sanitary District also had not given its approval for a permit for the clinic.

That earlier settlement ended up scuttled when the approval did not occur within the deadline set in the agreement. CRC then asked the federal court to put the lawsuit back on its schedule. Since the fall of 2012, the federal court has been considering motions filed by both sides.