A court ruling requiring Olympic running sensation Caster Semenya to lower her testosterone levels goes to the heart of a dilemma facing the sports world: How to avoid discrimination against intersex or transgender athletes while ensuring that competitions are fair.

The challenges faced by Semenya — a South African woman who reportedly has some intersex traits — differ in key respects from those confronting transgender women. But there are parallels as well, as evidenced in Wednesday's ruling by the Court of Arbitration for Sport, the sports world's highest court.

The court ruled that Semenya and other female runners with unusually high testosterone must take medication to reduce their levels of the male sex hormone if they want to compete in certain events, notably the 400 and 800 meters.

Comparable requirements apply to transgender women seeking to compete in the Olympics and in NCCA-governed collegiate sports in the U.S. Both organizations say male-to-female athletes should demonstrate that their testosterone level has been below a certain point for at least a year before their first competition.

In Semenya's case, the court voted 2-1 to uphold proposed rules issued by international track's governing body, the IAAF, saying that they are discriminatory but that "such discrimination is a necessary, reasonable and proportionate means" of "preserving the integrity of female athletics."

Athlete Ally, a U.S.-based group advocating for greater transgender inclusion in sports, assailed the ruling against Semenya.

"Forcing athletes to undergo medically unnecessary interventions in order to participate in the sport they dedicate their lives to is cruel and a violation of their human rights," said the group's executive director, Hudson Taylor.

Also angered was Kimberly Zieselman, executive director of InterACT, which advocates on behalf of intersex youth.

The ruling against Semenya "is another example of the ignorance faced by women athletes who have differences in their sex traits," Zieselman said in an email. "There is no one way to be a woman."

"It is an inherently flawed conclusion that Caster's natural testosterone level is the only thing giving her physical strength," Zieselman added. She noted — while citing swimmer Michael Phelps' long arms — that many athletes have unique physical advantages.

Powerful female stars such as Serena Williams in tennis, Katie Ledecky in swimming and 6-foot-9 (2-meter) Brittney Griner in basketball also have been cited as possessing a distinctive physical edge.

Aside from Semenya, there have been relatively few high-profile controversies involving intersex athletes, while there's been an abundance of news stories about transgender athletes.

Overall, supporters of increased trans inclusion in sports are heartened by the pace of progress. In the United States, a growing number of state high school athletic associations enable them to play on teams based on their gender identity, and the NCAA has trans-inclusive guidelines for all member schools.

But there have been numerous bitter controversies, even at the high school level. In Connecticut, for example, the dominance of transgender girl sprinters Terry Miller and Andraya Yearwood has stirred resentment among some competitors and their families.

At the adult level, USA Powerlifting incurred recent criticism for sticking by its policy of banning trans women from its competitions. The organization contends that regardless of testosterone levels, male-to-female competitors generally have significant advantages related to bone density and muscle mass.

Earlier this year, tennis great Martina Navratilova became entangled in the debate over trans women's place in sports.

FOLLOW NBC OUT ON TWITTER, FACEBOOK & INSTAGRAM