It’s never been easy being a sexual minority in Pakistan, but transgender citizens, known here as eunuchs or “hijras,” are getting a surprising amount of judicial protection and newfound civil rights.

Last month, they celebrated their most recent victory when they were allowed for the first time to register to vote identifying themselves as a third sex — transgender. In the past, state-issued identification cards listed individuals only as male or female.

The other day, in the august halls of the Supreme Court of Pakistan, a group of hijras — biological men who identify as women — gathered for the latest hearing on the enforcement of a constitutional-rights case brought in 2008 concerning “the humiliation of eunuchs.” In their flowing, brightly colored salwar kameezes — traditional tunics and pants — and head scarves, the small delegation drew sideways glances from lawyers and visitors alike as they conferred in the marble corridor before being summoned into the courtroom.

“Police used to beat us and take money from us,” said Almas Bobby, a leader of the transgender community of Rawalpindi, a large city near the capital. “It was painful for us. Now we go to the police station, and they respect us and they are afraid of us. They take our cases first. Now they feel we have rights.” Bobby, 40, said she was the first to receive an ID card with the new designation.

Eunuchs date back centuries — in the Mogul Empire, castrated men worked as harem guards and were highly esteemed as entertainers in the royal courts. But the term is broadly used in Pakistan today to describe varied groups, including transsexuals, transvestites, homosexuals, hermaphrodites and cross-dressers.

Traditionally, eunuchs here were seen as blessed, displaying characteristics of both sexes and often invited to weddings to bring good luck to newlyweds. But esteem gave way to social opprobrium and harassment with the rise of religious fundamentalism.

The court’s general orders to the government are that transgender persons must be treated as other citizens are — although, if qualified, they will be given preference for civil service jobs for affirmative-action reasons. A transgender applicant with a 10th-grade education is deemed to have the same qualifications for government work as a non-transgender person with a bachelor’s degree, according to one attorney working on the case.

The court has been monitoring the progress of the case through periodic hearings, about 20 so far.

Bobby’s parents are dead, and remaining family members are disapproving. Such scorn is not uncommon.

Because they are often disowned by their own family, hijras create a “shadow family” with someone who assumes the role of the fathers, mothers and brothers. “It is all fake, but they prefer it,” said Saleem Awan, secretary of the Social Welfare Department in Quetta, who came to court to report on compliance with the order. “They prefer to live with their own kind.”

Some transgender Pakistanis who have been abandoned by their family of origin are reluctant to acquire ID cards — even though they have the right to do so — because they do not wish to register under their father’s name as required under the rules. They would rather register under the name of their “guru,” the head of their chosen family. (Bobby is one such guru.)

Chief Justice Iftikhar Mohammed Chaudhry is known for latching onto various causes by using a judicial maneuver called suo motu notice, which allows the court to intervene on its own when other branches of government fail to address problems large and small.

“The chief justice says we are God’s creation,” Bobby said. “Now people have awareness. First they joked and teased us. Now they realize that we are human beings.”

“Chaudhry,” she said, adjusting her scarf before the hearing, “is a hero.”