The court found for the first time that federal civil rights law prohibiting workplace discrimination on the basis of sex also protects employees based on their sexual orientation or gender identity.

The 6-to-3 ruling, led by Justice Neil Gorsuch, largely turned on the meaning of the word “sex” within Title VII of the Civil Rights Act of 1964, which makes it unlawful for an employer to “discriminate against any individual” because of their sex.

There was little dispute that Congress did not intend to protect LGBT employees when it passed that landmark civil rights-era legislation. But over 50 years later, lawyers at the hight court tussled over whether sex-based protections must include protections for sexual orientation and gender identity by consequence.

Gorsuch—whose vote was anticipated due to his preference for emphasizing the text of the law itself over lawmakers’ intent—was joined by Chief Justice John Roberts and the court’s four liberal-leaning members: Justices Ruth Bader Ginsburg, Stephen Breyer, Elena Kagan and Sonia Sotomayor.

“Those who adopted the Civil Rights Act might not have anticipated their work would lead to this particular result. Likely, they weren’t thinking about many of the Act’s consequences that have become apparent over the years,” the court said. “But the limits of the drafters’ imagination supply no reason to ignore the law’s demands.”

The Trump administration intervened in the case with a brief arguing that terminating gay or lesbian employees wouldn’t constitute discrimination under Title VII because affected workers of both genders “would be similarly situated—and they would be treated the same.”

This is the first time the Supreme Court has addressed whether Title VII explicitly encompasses LGBT protections. But the court has ruled previously on gender-related issues, finding that prohibitions against sex discrimination necessarily forbid sex stereotyping: When a woman, for example, does not conform to her femininity in the way her employer might expect or desire.

The court’s 1989 ruling in Price Waterhouse v. Hopkins held that stereotyping employees based on gendered expectations violated Title VII. It is considered a cornerstone opinion and the plaintiffs invoked it repeatedly in arguing that discrimination based on an employee’s LGBT status ran afoul of the law.

The cases involved three individuals who say they were fired from their jobs for being either gay or transgender. Gerald Bostock was a welfare services coordinator for Clayton County, Georgia, in the early aughts. In 2013, after he began to discuss his participation in a gay softball league, his management of county funds was re-examined, and he was fired for “conduct unbecoming” of employees.

“There are no words to fully express Gerald Bostock’s sincere gratitude for the Supreme Court’s decision in his case,” his attorney, Thomas Mew, told Newsweek in a statement. “In a moment when so many are hurting and reeling from the injustices of inequality, this is a positive step in the right direction for equal rights. But there is still so much work to be done, as recent events underscore.”

Clayton County did not immediately return a request for comment.

The other two plaintiffs reported similar experiences with their employers. Donald Zarda, now deceased, was a longtime sky-diving instructor. During a dive in 2010, he reassured a female client about his sexual orientation in case there was a concern about being strapped together in close proximity. He was fired shortly thereafter and died during a sky-diving accident in 2014.

The skydiving company, Altitude Express, informed Zarda that he was terminated for inappropriately touching the client. However, the company later told the New York State Department of Labor that the firing was a result of Zarda sharing “inappropriate information” with customers “regarding his personal life.” Zarda denied wrongdoing, and after the accident, his federal lawsuit was continued on behalf of his estate.,

“When my brother told me that he was fired, I was shocked. I couldn’t believe that you could be fired for being gay,” Melissa Zarda, his sister, said in a news release as the case was being pursued, adding that she “thought that this had to be against the law” and hoped the Supreme Court would “see that what happened to my brother was wrong.”

Zarda’s lawyer told Newsweek following the news that he was gratified by the resolution of a long-shot campaign he had been waging for decades.

“I had a discussion with someone who is now a judge when I was in law school about this question and I thought, ‘He’s right,’” attorney Gregory Antollino said. “This is the case that I’ve been thinking about for 20 years. Of course when Don [Zarda] died I couldn’t give up, and I’m so glad I didn’t. I have no thoughts to collect, just emotions.”

“We are genuinely surprised by the court’s decision. The court clearly worked very hard to make sure that congressional inaction on LGBTQ+ rights would not go unrepaired. We no longer live in a society where a Gay couple can be married on Friday and fired for that marriage on Monday,” a lawyer for Altitude Express said in a statement.

“Although we maintain that Mr. Zarda was terminated for inappropriately touching a female customer we look forward to having a second jury clear Altitude Express of any wrongdoing just as the first jury trial revealed,” the statement continued.

Aimee Stephens, who died in May due to complications of kidney disease, was fired from her job as a funeral director in 2013 after coming out as a transgender woman.

In response to a request for comment, the American Civil Liberties Union, which represented Stephens, called the decision “a huge win for LGBT rights.”

“People must be judged by their abilities, not by their sex, sexual orientation, or gender identity,” the organization said.

Unlike the other two cases, the circumstances surrounding Stephens’ firing are less contested. Thomas Rost, the owner of Michigan-based R.G. & G.R. Harris Funeral Homes, said that Stephens adopting a more feminine gender presentation would violate the company’s dress code. Stephens presenting as female “would be violating God’s commands” in Rost’s view.

Though his lawyer says he did not object in principle to Stephens’ transgender status, her use of the same restrooms as other female clientele and staff caused Rost to become “concerned.”

An appeals court sided with Stephens and the Equal Employment Opportunity Commission, which brought the charge of Title VII discrimination on her behalf. The funeral home appealed that decision to the Supreme Court. After Stephens’ death, her wife Donna was substituted as a party to the case.

The Alliance Defending Freedom, which represented Harris Funeral Homes, called the decision “disappointing.”

“Americans must be able to rely on what the law says,” the group said in a statement. “Redefining ‘sex’ to mean ‘gender identity’ will create chaos and enormous unfairness for women and girls in athletics, women’s shelters, and many other contexts.”

In their brief before the Supreme Court, Bostock’s legal team argued that any decision other than guaranteeing full protections for LGBT employees would be “profoundly unworkable.”

They noted the conundrum that could result from probing the motives of an employer who seeks to dismiss his gay employee: Do the employee’s mannerisms offend the employer? Prohibited. Or does the employer’s objection stem from a more conceptual opposition to homosexuality? Permitted.

Drawing such a fine distinction between these kinds of anti-LGBT attitudes, the brief argued, “leads to confusing and contradictory results.”

Columbia Law School professor Suzanne Goldberg, who leads the school’s Center for Gender and Sexuality Law, told Newsweek that she believes many of these problems could be resolved through an evidentiary inquiry.

But, she said, there was ample room within court precedent to ensure that LGBT employees would be covered by Title VII, and believes such a ruling from the Supreme Court was the correct interpretation.

“Courts began to recognize some time ago, after Price Waterhouse, that drawing invisible lines between sex stereotyping of gay and non-gay employees does not make sense,” Goldberg said. “This is a non-partisan issue. These are straightforward questions about applying law that on its face tells employers they cannot treat an employee differently because of their sex or the stereotypes associated with their sex.”

This article has been updated with statements from parties involved in the cases.