U.S. District Judge William Alsup said Anderson must be freed because a federal appeals court hadn't affirmed the contempt order within the required 30 days after Anderson was jailed.
Anderson, 40, could be returned to prison if the appeals court affirms the Aug. 28 contempt citation.
The trainer has been imprisoned twice for refusing to testify before a grand jury investigating whether the Giants slugger committed perjury when he said he never knowingly used steroids.
Bonds told a 2003 grand jury investigating BALCO that Anderson gave him what he believed to be flaxseed oil and arthritic balm. Anderson later pleaded guilty to distributing steroids and money laundering, serving three months in prison and three months' home detention.
Anderson's latest jail stint lasted 37 days. He also served 15 days in July and was released when the previous grand jury expired.
He has appealed his contempt jailing on several fronts. Anderson's main contention is that a secret, illegally-recorded tape of him discussing Bonds' steroid use is the basis for the grand jury questions he refuses to answer.
Prosecutors, however, say the tape is legal and was made in a face-to-face meeting with Anderson.
Although Alsup dismissed Anderson's tape claim and others, the 9th U.S. Circuit Court of Appeal last week sent Anderson's appeal back to the judge, saying Alsup's ruling regarding the tape was not clear enough.
"This snafu has arisen by an apparent failure by the court to be clear of its findings," Alsup said.
In clarifying his order Thursday, Alsup said he agreed with prosecutors that there was ample evidence beyond the tape to question Anderson. Prosecutors on Thursday said the questions they want answered are based on athletes' secret testimony in the Bay Area Laboratory Co-Operative case and a search of Anderson's house that turned up drug records, some with Bonds' name on it.
The appeals court could rule any day.
Other than the tape dispute, the 9th U.S. Circuit Court of Appeals has rejected the merits of Anderson's appeal. Among them, Anderson said his BALCO plea deal prevented him from cooperating with the government's steroid investigation.
Anderson also will seek to withdraw his 2005 guilty plea because his lawyer, Mark Geragos, said the tape amounts to an illegal wiretap and may have been the basis for the case.