The US Supreme Court delivered a landmark victory for the gay and transgender communities on Monday when it ruled that employers cannot discriminate against workers because of their sexual orientation.

In a blow to the administration of President Donald Trump, the court ruled by six votes to three that Title VII of the Civil Rights Act of 1964, which outlaws discrimination against employees because of a person’s sex, also covers sexual orientation and transgender status.

“Today we must decide whether someone can be fired simply for being homosexual or transgender,” the court said. “The answer is clear.”

Gerald Bostock, one of the plaintiffs, said he was in “shock”.

“But trust me when I say my heart is just full, I am so excited and happy,” he said.

“No one has to be fearful going to work, fearful that they could lose their job because of who they are, who they love or how they identify,” Bostock said, though he noted there was still “a lot of work to be done”.

Trump’s administration had effectively thrown in its lot with employers, but the president later on Monday called the ruling “very powerful”.

Lesbian, gay, bisexual and transgender rights activists, as well as Democratic politicians and several major businesses, had been demanding that the court spell out that the community was protected by the law.

“This is a huge victory for LGBTQ equality,” said James Esseks, director of the American Civil Liberties Union’s LGBTQ & HIV Project.

The group uses the longer version of the acronym, in which the Q stands for “questioning” – as in still exploring one’s sexuality – or “queer”.

“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,” he said in a statement.

Joe Biden, the Democratic nominee for president, hailed the decision as “a momentous step forward for our country”.

Biden was vice-president when the court made its historic ruling in favour of same sex marriage in 2015.

Rights activists had feared that Trump’s appointment of two new conservative judges to the top court could hinder further wins for their cause.

Yet it was one of them, Neil Gorsuch, who wrote the majority decision, joining with the court’s four progressive-leaning judges and Chief Justice John Roberts.

He said: “An employer who fires 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. 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.

“But the limits of the drafters’ imagination supply no reason to ignore the law’s demands.”

Solicitor General Noel Francisco, representing the government’s position before the court, argued that “sex refers to whether you were born woman or man, not your sexual orientation or gender identity”.

He said it was the job of Congress to update the law, not the justice system.

The Alliance Defending Freedom, a Christian religious freedom group, said the court’s decision was “truly troubling” and encroached on the religious beliefs of employers.

Along with Bostock’s case the court considered two others, including that of transgender plaintiff Aimee Stephens.

Donna Stephens, the wife of Aimee who died last month, hailed her late partner’s struggle for justice after being sacked by a Detroit funeral parlour when she came out.

Stephens said in a statement: “I am grateful for this victory to honour the legacy of Aimee, and to ensure people are treated fairly regardless of their sexual orientation or gender identity.”

Among Democratic leaders hailing the ruling was Pete Buttigieg, the former Navy officer and mayor who became the first openly gay person to run for the Democratic presidential nomination.

“It was only 11 years ago this summer that I took an oath and accepted a job that I would have lost, if my chain of command learned that I was gay. Firing us wasn’t just permitted – it was policy,” he said.

Pop superstar Taylor Swift also lauded the decision, tweeting: “We still have a long way to go to reach equality, but this is a beautiful step forward.”