PYEONGCHANG, South Korea — The International Olympic Committee on Sunday dealt Russia one final punishment at these Winter Games, upholding a ban on Russia’s Olympic federation and preventing the country’s athletes from marching in the Closing Ceremonies with their tricolor flag.

Though the ruling squashed Russia’s short-term hopes, the IOC also opened the door for the country to quickly escape its sporting ostracism after the Games are over. If no additional Russian athletes fail doping tests — a process that will play out in the coming days — the penalties against the nation will be promptly lifted, IOC President Thomas Bach said.

At a news conference, Bach said Russia squandered the chance to carry its flag in the Closing Ceremonies when two of its athletes, over the last two weeks, tested positive for banned substances. In the aftermath, pressure mounted on the IOC to maintain sanctions that were put in place nearly three months ago, the penalty for Russia’s long-running, nationwide doping operation.

Those failed tests were “hugely disappointing,” Bach said.

Russians have participated in these Games as neutral athletes, not as representatives of their own country. The participation of those 168 athletes was part of a compromise in which the IOC punished the Russian Olympic committee — charging it with a $15 million fine — but tried not to penalize those with no history of doping. In PyeongChang, the Russians wear plain uniforms that say, “Olympic Athlete from Russia.” They were not permitted to brandish the Russian flag, post about Russia on social media, nor complain publicly about the ban. If they won medals, they would hear not the Russian anthem, but the Olympic one.

Eleven of the best photos from today?s 2018 Winter Olympics

Max Parrot of Canada competes in the snowboard big air finals. (Clive Mason)

Though Russia’s men’s hockey team won a gold medal on Sunday, defeating Germany, Russia’s athletes have largely struggled at the Winter Olympics — claiming just 17 medals, two of them gold. At Sochi in 2014, Russia won 33 medals, most of any country, but more than a dozen of those medals have since been stripped for doping violations.

The IOC said Sunday that Russia had largely followed the terms of its punishment — except for the additional doping violations.

During these Olympics, Russians have accounted for two of the four positive doping tests. Athletes from Japan and Slovenia also tested positive. Alexander Krushelnitsky, competing in mixed doubles curling, tested positive for banned substance meldonium and returned his bronze medal. Then, bobsledder Nadezhda Sergeeva tested positive for trimetazidine, a medication for heart disease that also affects metabolism. Earlier during the Olympics, for a promotional video, she wore a shirt saying, “I don’t do doping.”

In an open letter to IOC members published Friday, the Institute of National Anti-Doping Organisations said that the “clean athletes of the world would be outraged” if Russia’s ban was lifted.

“By failing to impose a meaningful sanction on [Russia’s Olympic committee], the IOC would be culpable in this effort to defraud clean athletes of the world,” the institute wrote. “Clean athletes continue to raise concerns and are understandably frustrated with the equivocal stance of the IOC when it comes to the systemic doping in Russia.”

However, in a report released Sunday, the IOC described the two positive tests by Russian athletes as “individual and isolated cases” that did not reflect “systemic” and organized doping. The IOC said that both Krushelnitsky and Sergeeva had been tested “numerous times” beforehand, and their samples were never positive.

In a statement, Russia’s Olympic Committee said that it hoped its membership in the IOC would be fully restored within “the next few days.”

The IOC met over two days this weekend to determine Russia’s fate, and on Saturday they heard from Stanislav Pozdniakov, the head of the Olympic Athlete from Russia (OAR) delegation in PyeongChang, who said the anti-doping violations had more to do with “negligence than malicious intent.”

“Our anti-doping system has been restructured completely,” Pozdniakov said. “A lot has been done and a lot still needs to be done. Fighting for clean athletes is our common cause and we will stay the course.”

Still, distrust of Russia runs deep, and over the last few years, the IOC has built a mountain of evidence documenting the Russian doping program, one that Olympic officials believe was supported by government officials in Moscow. Evidence of that program was detailed in a series of investigations by the World Anti-Doping Agency, but the most powerful part of the case was provided by a whistleblower, Grigory Rodchenkov, who once ran Russia’s anti-doping laboratory. Rodchenkov fled for the U.S. in 2015 and is living under federal protection.

The athletes of the U.S. biathlon team said Friday that they would boycott a World Cup event in Russia next month.

“We fully support the right of clean Russian athletes to compete and share the opinion that Russia should be eligible to host” future World Cups, the statement said. “But only after they have shown a meaningful commitment to rectifying the doping culture which has been shown to exist there.”

“I absolutely followed orders,” Rodchenkov told the BBC. “It was teamwork. FSB [Russian State Security Services] was involved when we had to control coordination. [Mutko] knew absolutely everything, and he reported to the president. I know he reported to Putin — he told me that.”

Rodchenkov said that reinstating Russia would be the IOC’s “worst decision.”