TOKYO — Japan’s highest court on Wednesday upheld a law dating back more than a century that requires married couples to share the same surname, rejecting a claim that it discriminates against women by effectively forcing them to give up their names in favor of their husbands’.

The ruling was a blow to Japanese women seeking to keep their maiden names after marriage. Some couples have chosen not to register their marriages — opting instead to stay in common-law relationships with fewer legal protections — in order to keep separate surnames.

“When I heard the ruling I started crying, and even now it hurts,” said Kyoko Tsukamoto, 80, a retired high school teacher who was one of five plaintiffs trying to overturn the law.

Ms. Tsukamoto, whose legal married name is Kojima, said she had “lost her identity” because of the ruling. She and her husband of 55 years registered their marriage decades ago only because they wished to prevent their three children from being born out of wedlock, which carries a strong stigma in Japan. They divorced and remarried between the children’s births, she said, to protest the law.