The Court of Arbitration for Sport has upheld the appeals of 28 Russians were who banned by the International Olympic Committee for doping at the 2014 Winter Games in Sochi.
The court found there was "insufficient" evidence that the athletes had broken doping rules.
Sport's highest court partially upheld the appeals of 11 others, reducing their life bans to suspensions which cover this month's Games in Pyeongchang.
The decision to clear so many of the banned Russians is a huge blow to the IOC's approach to the Russian state-sponsored doping scandal and will be greeted with fury by athletes and anti-doping groups around the world.
In a statement, the IOC greeted the decision from CAS with "satisfaction on the one hand and disappointment on the other".
While welcoming the ruling to confirm the doping violations committed by 11 athletes, the IOC said it "regrets very much - according to the CAS press release - the panels did not take this proven existence of the systemic manipulation of the anti-doping system into consideration for the other 28 cases.
"The CAS required an even higher threshold on the necessary level of evidence than the Oswald Commission and former CAS decisions."
The statement added that this "may have a serious impact on the future fight against doping. Therefore, the IOC will analyse the reasoned decisions very carefully once they are available and consider consequences, including an appeal to the Swiss Federal Tribunal."
The IOC also said that the 28 athletes cleared by CAS remained ineligible to compete in Pyeongchang due to the suspension of the Russian Olympic Committee, which means Russian athletes may only compete on invitation by the IOC.
"The result of the CAS decision does not mean that athletes from the group of 28 will be invited to the Games," the statement said.
"Not being sanctioned does not automatically confer the privilege of an invitation. In this context, it is also important to note that, in his press conference, the CAS secretary general insisted that the CAS decision '...does not mean that these 28 athletes are declared innocent'."
Among those now cleared of cheating at Sochi 2014 are men's Olympic skeleton champion Aleksander Tretiakov, the current women's European and World Cup skeleton champion Elena Nikitina and Olympic cross-country gold medalist Alexander Legkov.
Aleksandr Zubkov, the double Olympic bobsleigh champion and Russian flag-bearer in Sochi, is among the 11 whose anti-doping rule violations have been upheld, though, as have those of three members of the Russia's second unit in the men's four-man bob in 2014.
The 39 appeals were heard in two batches in Geneva last week, with all but two athletes attending in person.
They were heard via video link.
Also appearing via video were their two chief accusers, the former head of the Moscow anti-doping laboratory Dr Grigory Rodchenkov, who fled to the United States in 2015 and has become the main whistleblower in the Russian doping scandal, and Professor Richard McLaren, the legal expert who examined Rodchenkov's claims on behalf of the World Anti-Doping Agency.
McLaren's landmark report, which was published in December 2016, revealed documentary, forensic and supporting witness testimony to corroborate Rodchenkov's story of an increasingly sophisticated conspiracy to dope more than 1,000 Russian athletes, across 30 sports, over at least five years and two Olympic Games.
Converting that evidence into individual doping cases, however, has proved to be very difficult, as the IOC has just discovered, despite setting up two bespoke disciplinary commissions to build on McLaren's work and prosecute athletes.
One of those commissions, led by former Swiss president Samuel Schmid, was the basis of December's decision by the IOC to suspend the Russian Olympic Committee, which means Russia must send a neutral team of 'Olympic Athletes from Russia' to Pyeongchang, with no right to use the Russian anthem or flag in the opening or medal ceremonies.
But it is the work of the commission led by IOC member Denis Oswald that CAS has picked apart, as his job was to prosecute anti-doping cases against individuals, which meant proving their 'dirty' urine samples were swapped for 'clean' ones in Sochi.
In a statement, CAS said: "Both CAS panels unanimously found that the evidence put forward by the IOC in relation to this matter did not have the same weight in each individual case.
"In 28 cases, the evidence collected was found to be insufficient to establish that an anti-doping rule violation (ADRV) was committed by the athletes concerned. With respect to these 28 athletes, the appeals are upheld, the sanctions annulled and their individual results achieved in Sochi 2014 are reinstated.
"In 11 cases, the evidence collected was found to be sufficient to establish an individual ADRV. The IOC decisions in these matters are confirmed, with one exception: the athletes are declared ineligible for the next edition of the Olympic Winter Games instead of a life ban from all Olympic Games."
The decision to lift the life ban was widely expected, as CAS has previously ruled against attempts to go beyond the sanctions allowed by the WADA Code before, but the 28 successful appeals throw the IOC's belated attempts to get tough with Russia into turmoil.
CAS added that its panels were not trying "to determine generally whether there was an organised scheme allowing the manipulation of doping control samples in the Sochi laboratory" but were only focused on whether there was enough evidence to ban individuals.
The appeals of three more Russians, all biathletes, will be heard after the 2018 Winter Games, which run from February 9-25.
A statement from Rodchenkov's lawyer, Jim Walden, said the decision from CAS made it "harder for clean athlets to win".
"Dr. Rodchenkov testified fully and credibly at CAS," the statement said. "His truth has been verified by forensic evidence, other whistleblowers, and, more recently, recovery of the Moscow lab's secret database, showing thousands of dirty tests that were covered up.
"This panel's unfortunate decision provides a very small measure of punishment for some athletes but a complete 'get out of jail free card' for most. Thus, the CAS decision only emboldens cheaters, makes it harder for clean athletes to win, and provides yet another ill-gotten gain for the corrupt Russian doping system generally, and (president Vladimir) Putin specifically."