Caster Semenya, a two-time Olympic champion runner, has lost her appeal against proposed rules to limit her testosterone levels in what could be a pivotal moment for athletics and gender in sport.

The ruling means Semenya will have to begin medically reducing her testosterone levels within the next week if she wants to compete in the world championships in Doha, Qatar, in September.

The South African runner, who won gold in the 800 meters in 2012 and 2016, was challenging proposals brought by the sport's governing body -- the International Association of Athletics Federations (IAAF) -- to enforce limits on testosterone levels of female athletes with differences in sexual development (DSDs).

The Court of Arbitration for Sport's panel of three judges gave a complex verdict but ultimately rejected Semenya's case in favour of the governing body's desire to protect fair competition among female athletes.

The judges decided the IAAF's proposed rules are discriminatory, but they also found in a 2-1 verdict that "on the basis of the evidence submitted by the parties, such discrimination is a necessary, reasonable and proportionate means of achieving the IAAF's aim of preserving the integrity of female athletics in the Restricted Events [races of distances between 400m and a mile]."

Despite ruling against Semenya, 28, the panel of judges raised "serious concerns" over how the IAAF's rules will be practically applied.

In a summary of its 165-page document, the judges said it was possible for athletes to unintentionally be over the proposed testosterone levels because they are too strict, and that the side effects of hormone treatment could make it difficult for athletes to comply.

In the wake of the verdict, Semenya said she had been targeted by the IAAF. In a statement released by her lawyers, she said: "I know that the IAAF's regulations have always targeted me specifically. For a decade the IAAF has tried to slow me down, but this has actually made me stronger.

"The decision of the CAS will not hold me back. I will once again rise above and continue to inspire young women and athletes in South Africa and around the world."

In response to the verdict, she tweeted:

Dr. Payoshni Mitra, a gender expert who testified in the case for Semenya, told ESPN: "Honestly, we were hoping for a favorable verdict. All the same, I don't look at it as a blow. It must be noted that all three judges have described the DSD regulation 'discriminatory' and also expressed serious doubts about how it will be implemented. We also need to take note that it was a majority decision not a unanimous one.

"We have the option of an appeal to the Swiss Federal Court within the next 30 days. It's a possibility. I am sure Caster will discuss with her legal team.

"Caster has been fighting this battle for over a decade now. She has been withstanding severe scrutiny and yet had the resilience and determination and commitment to fight it. Personally, I have been working on this issue for a decade, too."

Mitra was the Indian government-appointed adviser in the Dutee Chand case and was at the forefront of the fight that led to the landmark ruling in 2015. Mitra said: "Very few people thought we'd win the Dutee case back in 2015, but we did. I am fortunate to have had the opportunity to work closely with courageous women like Dutee and Caster. I draw my strength from them and I can tell you that none of us will ever give up."

Meanwhile, the IAAF said it was "grateful" to CAS for its detailed response to the case and said it was happy with the result.

"The IAAF ... is pleased that the Regulations were found to be a necessary, reasonable and proportionate means of achieving the IAAF's legitimate aim of preserving the integrity of female athletics in the Restricted Events," a statement from the organisation said.

"No athlete will be forced to undergo any assessment and/or treatment under these regulations. It is each athlete's responsibility, in close consultation with her medical team, to decide whether or not to proceed with any assessment and/or treatment.

"The regulations will come into effect on 8 May 2019 at which time all relevant athletes wishing to compete in the female classification in a Restricted Event at an international competition need to meet the eligibility conditions."

South Africa's sports minister, Tokozile Xasa, said the proposed IAAF regulations breached Semenya's human rights.

"Naturally we are disappointed with the judgment," Xasa said. "We will study the judgment‚ consider it and determine a way forward.

"As the South African government we have always maintained that these regulations trample on the human rights and dignity of Caster Semenya and other women athletes."

Former distance runner Paula Radcliffe of Britain defended CAS, saying it had been faced with a difficult judgment.

"I understand how hard a decision this was for CAS and respect them for ruling that women's sport needs rules to protect it," Radcliffe said.

In April 2018, the IAAF introduced new rules that meant female athletes with differences in sexual development would have to bring their testosterone levels in line with those of other female athletes.

The IAAF argued it was preserving fair competition, but Semenya -- aware that the rules would have a significant impact on her career -- believed she was being discriminated against and took her case to CAS.

The IAAF decided to postpone bringing in the new rules in November until after Semenya's appeal had been heard.

Before the case, the South African government called on the world to fight what it called a "gross violation" of Semenya's human rights, an argument echoed by the United Nations Human Rights Council a month later.

CAS heard the arguments of both sides in February in Lausanne, Switzerland, and has been deliberating in the months since, finally reaching its verdict Wednesday.

People who have differences in sexual development can have both male and female characteristics. They may have a different genetic makeup and, crucially, have higher-than-average testosterone levels for female athletes.

The IAAF argued that any athlete in this category -- which includes Semenya -- would have a large advantage over other female athletes because heightened testosterone levels can make it easier to increase muscle size and strength.

Semenya arriving at court for the start of her hearing in February. Harold Cunningham/AFP/Getty Images

The organisation has repeatedly said it has a duty to ensure the playing field is level and competition is fair, which led it to introduce its new rules.

Semenya's legal team argued there were many genetic variations at play across sport and said she was being discriminated against as a woman.

They argued she was "born, reared and socialised" as a woman, and as such should be allowed to compete as one.

They also said it was ethically wrong and potentially harmful to force her to reduce her testosterone levels medically.

The IAAF's new rules go into effect on May 8, which means any athlete in Semenya's situation who wants to compete at the world championships in September will have to start taking medication before then.

The rules state that an athlete must not compete for six months after reducing their testosterone levels, but the IAAF has made a special concession because of how long it took CAS to reach a verdict.

Semenya could decide to undergo testosterone-reducing treatment in the next week to continue running the 800 meters, but her lawyers have previously argued she could be as much as seven seconds slower if she does and would likely lose her status as a dominant champion of the event.

She could also change her event and compete at a distance outside the limits imposed by the IAAF, a possibility that has moved closer since she won the 5,000 meters at the South African championships a week ago.

Other athletes will also be affected, among them the 2016 Olympic 800-meter silver medalist, Francine Niyonsaba of Burundi.