(CNN) In a scathing decision, a federal judge blasted a subsidiary of the nation's largest insurance company for focusing on the "bottom line as much or more" than patients' health, saying the insurer illegally denied treatment to thousands of people. The judge also slammed the company's medical directors for being "deceptive" under oath.

US Chief Magistrate Judge Joseph Spero issued his decision Tuesday against United Behavioral Health, a unit of UnitedHealthcare, saying the insurer created internal policies that effectively discriminated against those seeking mental health and substance abuse treatment.

"It is well-established that effective treatment of mental health and substance use disorders includes treatment aimed at preventing relapse or deterioration of the patient's condition and maintaining the patient's level of functioning. UBH Guidelines deviate from that standard," Spero said.

Legal observers called the decision one of the most important and most thorough rulings ever issued against an insurance company, at the federal level, on mental health issues.

Patrick Kennedy, the former US representative from Rhode Island who has long championed mental health issues , called the ruling "breathtaking" in its scope. For the mental health community, he equated it to the landmark 1954 Supreme Court decision that found racial segregation in public schools unconstitutional.

"This ruling is the Brown v. Board of Education for the mental health movement," Kennedy said. "The insurance industry is hellbent on violating the federal law, and they're doing so with impunity. Now, we have a federal court specifically and forensically breaking down how they get around the federal law."

The class-action suit was brought on behalf of more than 50,000 people denied coverage by United Behavioral Health, the country's largest managed behavioral health care organization.

Spero took more than a year to issue his 106-page decision. In addition to finding federal violations, Spero ruled that United Behavioral Health violated state laws in Illinois, Connecticut, Rhode Island and Texas.

The judge blasted United Behavioral Health's medical directors and other expert witnesses who set the company's policies -- naming each one before shredding them as not credible and discounting their testimony.

"UBH's experts, on the other hand, had serious credibility problems," Spero wrote. "The Court found that with respect to a significant portion of their testimony each of them was evasive -- and even deceptive -- in their answers when confronted with contrary evidence."

He said one board-certified psychiatrist and senior medical director, whose duties included supervising and training United Behavioral Health care advocacy clinicians, "was not always credible because in several instances he ignored the plain meaning of the words used in the Guidelines."

Another United Behavioral Health expert whose duties included drafting coverage determination guidelines, the judge said, implemented a "model that keeps benefit expenses down by placing a heavy emphasis on crisis stabilization and an insufficient emphasis on the effective treatment of co-occurring and chronic conditions."

The judge said such decisions had real impacts on patients because United Behavioral Health ignored "effective treatment of members' underlying condition" and that "UBH knowingly and purposefully drafted its Guidelines to limit coverage to acute signs and symptoms."

"Research has demonstrated that patients with mental health and substance use disorders who receive treatment at a lower level of care than is clinically appropriate face worse outcomes than those who are treated at the appropriate level of care," Spero said in his ruling.

He concluded by saying one of the driving factors for such policy decisions was the company's profit motivations: "Finally, the evidence at trial established that the emphasis on cost-cutting that was embedded in UBH's Guideline development process actually tainted the process, causing UBH to make decisions about Guidelines based as much or more on its own bottom line as on the interests of the plan members."

The ruling was issued in the US District Court for the Northern District of California. It will now move to a remedy phase in which the judge is to determine how the insurer should be punished.

Brian Hufford, one of the lead attorneys for the plaintiffs, said the case peeled back the layers of coverage decisions made by insurers that most policy holders don't even know happen behind the scenes. He said the judge's decision highlighted the fact United Behavioral Health was "making decisions that are influenced by their monetary concerns and what profits they can make."

"This case involved coverage of benefits for the most vulnerable population -- people who suffer from mental illness and substance abuse," Hufford said. "Historically insurance companies have been able to hide that conduct and save money by denying treatment to these people in need."

Meiram Bendat, an attorney and psychotherapist with the law firm Psych-Appeal who uncovered the guideline flaws, said the ruling was "vindication of what patients, providers, and the plaintiffs have been telling UBH for years -- that the nation's largest mental health insurer has been denying access to care on the false premise that 'crisis' should be the litmus test for coverage."

UnitedHealthcare took issue with the judge's comments about its medical directors, saying they "followed nationally accepted standards in reviewing these requests."

"We look forward to demonstrating in the next phase of this case how our members received appropriate care," UnitedHealthcare said in a written statement. "We remain committed to providing our members with access to the right care for the treatment of mental health conditions and substance use disorders."

The National Alliance on Mental Illness, or NAMI, the nation's largest advocacy group for the mentally ill, hailed the decision.

"This is a day NAMI has long awaited," said Angela Kimball, NAMI's national director of advocacy and public policy. "For decades, people with mental health conditions have experienced really horrific discrimination at the hands of health insurance plans. They routinely deny mental health care and often with tragic outcomes."

She added, "This is absolutely an incredibly important decision."

Speaking to CNN by phone, Kennedy called the judge's ruling "scathing and breathtaking at the same time. I think, frankly, it can be used to understand how all the insurance companies are doing this."

Get CNN Health's weekly newsletter Sign up here to get The Results Are In with Dr. Sanjay Gupta every Tuesday from the CNN Health team.

"Given the fact United is the largest insurer in the country, this is a very disturbing decision, and it has implications for United that they really haven't come to grips with."

He said that the decision is made even more important because it comes at a time when life expectancy in America has been going down because of a "public health crisis in mental health and addiction."

"The notion that the largest insurer in the nation is denying care for a set of illnesses that is the driving reason we have higher death rates in this country," Kennedy said, "you can't make this stuff up."