Eunuchs are seen as social outcasts by Pakistan's largely conservative society
Pakistan's Supreme Court says eunuchs must be allowed to identify themselves as a distinct gender in order to ensure their rights.
The eunuchs, known as "hijras" in Pakistan, are men castrated at an early age for medical or social reasons.
The court said they should be issued with national identity cards showing their distinct gender.
The government has also been ordered to take steps to ensure they are entitled to inherit property.
'Respect and identity'
There are estimated to be about 300,000 hijras in Pakistan and they are generally shunned by the largely Muslim conservative society.
They tend to live together in slum communities, surviving through begging and by dancing at weddings and carnivals.
A hijra association has welcomed the order, saying it is "a major step giving respect and identity in society".
Indian authorities last month agreed to list eunuchs and transgender people by using the term "others", distinct from males and females, on electoral rolls and voter identity cards, after a long-running campaign by the members of the community.