(Washington, D.C.) The U.S. Supreme Court ruled Monday that existing federal law forbids job discrimination on the basis of sexual orientation or transgender status, a major victory for advocates of gay rights and for the nascent transgender rights movement — and a surprising one from an increasingly conservative court.

By a vote of 6-3, the court said Title VII of the Civil Rights Act of 1964, which makes it illegal for employers to discriminate because of a person’s sex, among other factors, also covers sexual orientation and transgender status. It upheld rulings from lower courts that said sexual orientation discrimination was a form of sex discrimination.

Equally surprising was that the decision was written by President Donald Trump’s first Supreme Court appointee, Neil Gorsuch, who was joined by Chief Justice John Roberts and the court’s four more liberal members to form a majority.

“An employer who fired an individual for being homosexual or transgender fires that person for traits or actions it would not have questioned in members of a different sex,” Gorsuch wrote for the court. “Sex plays a necessary and undisguisable role in the decision, exactly what Title VII forbids.”

“Those who adopted the Civil Rights Act might not have anticipated their work would lead to this particular result,” he wrote, adding, “But the limits of the drafters’ imagination supply no reason to ignore the law’s demands.”

“Only the written word is the law, and all persons are entitled to its benefit,” he wrote.

Across the nation, 21 states have their own laws prohibiting job discrimination based on sexual orientation or gender identity. Seven more provide that protection only to public employees. Those laws remain in force, but Monday’s ruling means federal law now provides similar protection for LGBTQ employees in the rest of the country.

Gay and transgender rights groups considered the case a highly significant one, even more important than the fight to get the right to marry, because nearly every LGBTQ adult has or needs a job. They conceded that sexual orientation was not on the minds of anyone in Congress when the civil rights law was passed. But they said when an employer fires a male employee for dating men, but not a female employee who dates men, that violates the law.

Gay rights advocates celebrated the ruling. “The Supreme Court’s clarification that it’s unlawful to fire people because they’re LGBTQ is the result of decades of advocates fighting for our rights,” said James Esseks, director of the American Civil Liberties Union’s Lesbian Gay Bisexual Transgender & HIV Project. “The court has caught up to the majority of our country, which already knows that discriminating against LGBTQ people is both unfair and against the law.”

The ruling was a victory for Gerald Bostock, who was fired from a county job in Georgia after he joined a gay softball team, and the relatives of Donald Zarda, a skydiving instructor who was fired after he told a female client not to worry about being strapped tightly to him during a jump, because he was “100 percent gay.” Zarda died before the case reached the Supreme Court.

Courtesy of Pete Williams and NBC News