It would make Germany the first European country to offer intersex people the choice of identifying as neither male nor female.
The case was brought by a registered female whose chromosome test confirmed they were neither one sex nor the other.
Activists described it as a "small revolution".
The constitutional court in Karlsruhe has given the government until the end of 2018 to pass a law specifying a category other than male or female.
It said current regulations on civil status were discriminatory against intersex people.
The category could be called "inter" or "various".
A German government spokesperson said the government would comply with the ruling.
The activist group Third Option - which has been campaigning for official recognition - said on Twitter that it was "completely overwhelmed and speechless".
Intersex people are born with a mixture of male and female sex characteristics. The UN says the condition affects up to 1.7% of the world's population.
They are already recognised on official documents in countries including Australia, India, New Zealand, Nepal and the US, where the first intersex birth certificate was issued last year.
In Germany it has been possible since 2013 to leave the gender box blank on the birth certificate for people born with characteristics of both males and females. Before that, if there was any doubt, officials would enter either male or female.
In January Belgian model Hanne Gaby Odiele revealed that she was intersex, saying she hoped that it would "break the taboo".
But in May France's top appeals court ruled against offering a "neutral" gender designation to a 66-year-old psychotherapist born with neither a penis nor vagina and officially registered as a man.
The French court said the distinction between male and female was a "cornerstone" of social and legal organisation, and recognising a third gender would involve "numerous legislative changes," the New York Times reported.
Photo copyright: GETTY IMAGES (Caption: Birth certificates should carry a gender option for intersex people, the ruling says)