Current regulations on civil status are discriminatory against intersex people, the Federal Constitutional Court said, noting that the sexual identity of an individual is protected as a basic right.
Legislators must by the end of 2018 pass a new regulation to offer a third gender option in birth registers, the court added, ruling in favour of an appeal brought by an intersex person.
In the meantime, courts and state authorities should no longer compel intersex people to choose between identifying as male or female, said the top court.
The plaintiff had brought the appeal after several lower courts had ruled against a bid to introduce the gender options “inter” or “various” in the birth register.
The intersex person was registered as female, but a chromosome analysis found the plaintiff to be neither male nor female.
Intersex is a broad term encompassing people who have sex traits, such as genitals or chromosomes, that do not entirely fit with typical binary notion of male and female.
So intersex people would have features that are neither wholly female nor wholly male, or a combination or neither.
Berlin pledged to follow through with the ruling, with interior ministry spokesman Johannes Dimroth saying that the government “stands ready to implement it”.
The activist group Third Option was bursting with joy over the ruling.
“We are completely overwhelmed and speechless. That's a small revolution in the gender area,” it said on Twitter.
Under current rules, Germany allows babies born with characteristics of both sexes to leave the gender options of male and female blank.
The law is intended to remove pressure on parents to quickly make a decision about controversial sex assignment surgeries for newborns, but many advocates say it does not go far enough.
Wednesday's court ruling therefore takes a big step forward, by requiring a new gender option from birth.
According to the United Nations, between 0.05 and 1.7 percent of the global population is intersex – about the same percentage that have red hair.
Sometimes this is apparent at birth, at other times it becomes noticeable in puberty. Some may have chromosomes of either or both genders, although this may not be physically evident.
People who identify as intersex are recognized on official documents in some countries, including Australia, India, New Zealand and Nepal.
Belgian runway model Hanne Gaby Odiele significantly raised awareness of neutral gender issues earlier this year by publicly revealing that she is intersex.
New York, America's largest and one of its most liberal cities, last year issued the first US birth certificate marked “intersex”.
But in May, France rejected “neutral sex” on official documents, with its highest appeals court ruling against a request by a person born with neither a penis nor vagina.