Max Ary, who ran the museum, resigned in 2002. After that, it was discovered that some of the artifacts, including the moon bag, were missing.

The bag was found in Mr. Ary’s garage in 2003; two years later, he was convicted on multiple counts of fraud, theft and money laundering.

The critical error came when the bag was turned over to the government. It was identified as a different bag — one that had not been used to collect moon rocks — because of “a mix-up in inventory lists and item numbers,” according to Judge Marten’s decision.

The government included it in an online auction, and in February 2015, Ms. Carlson saw it and bought it, not knowing the true value.

The story might have ended there had she not sent the bag to the Johnson Space Center in Houston to check its authenticity. There, NASA realized what it had: a priceless artifact, still bearing traces of lunar dust, which should have been in its own custody all along.

So NASA kept the bag. Ms. Carlson sued to get it back.

In his December decision, Judge Marten concluded that the sale stemmed from an unfortunate mishap in which NASA was “the victim.” He nevertheless left the door open for Ms. Carlson’s lawsuit, and a federal court in Houston ruled in her favor in February.

Ms. Carlson could not be reached for comment on Wednesday, but Sotheby’s said that she planned to donate some of the proceeds of the sale to charities including the Immune Deficiency Foundation and a children’s health center.