SAN FRANCISCO - Surrounded by lawyers while fans chanted his name, Barry Bonds left court yesterday after pleading not guilty to charges he lied to federal investigators about using performance-enhancing drugs.

The home-run king was arraigned in U.S. District Court on four counts of perjury and one of obstruction of justice stemming from a Nov. 15 indictment. If convicted, he could spend more than two years in prison.

Bonds appeared relaxed as he smiled and chatted with his cadre of six attorneys. He then stood before the judge with his hands clasped behind his back and said: "I'm Barry Bonds."

Newly hired defense attorney Allen Ruby entered the plea on Bonds' behalf.

"Barry Bonds is innocent," Ruby said after the hearing. "He has trust and faith in the judicial system."

Ruby also said he soon would ask a judge to toss out the case against Bonds because of "defects" in the indictment. He declined to elaborate.

A judge declined the government's demand that Bonds turn over his passport and restrict his travel to within the United States. Ruby said such a restriction would interfere with his job as a Major League Baseball player. Bonds, a free agent after parting ways with the San Francisco Giants at the end of the 2007 season, hopes to play for a new team in 2008.

Bonds, who made nearly $20 million last year, was released without having to post any money. If he violates any terms of his release, including appearing at all required hearings, he'll be required to forfeit $500,000.

Bonds also had been expected to be booked and have his mug shot taken, but Ruby told the judge that happened Thursday.

A small gathering of fans chanted "Barry, Barry" as he waded through a crush of reporters, photographers and television cameras. He waved to his supporters, departing with his wife, Liz, in the same black sports-utility vehicle in which he arrived.

Bonds wore a dark blue suit and tie and said little during his 30 minutes in court. He quietly answered "yes" when asked if he understood he had a right to counsel and that if he couldn't afford a lawyer, one would be appointed for him.

A federal grand jury charged Bonds with repeatedly lying when he testified under oath that he never knowingly used performance-enhancing drugs.

Several of Bonds' former associates are expected to contradict that testimony, and prosecutors claim to have a blood test from November 2000 that shows a "Barry B" testing positive for two types of steroids.

But for all the speculation and accusations that hung over him as he chased Hank Aaron's milestone, Bonds has never been identified by Major League Baseball as testing positive for steroids.

Former San Francisco Giants teammates and other players, including Detroit Tiger Gary Sheffield and New York Yankee Jason Giambi, also could testify if Bonds takes the case to trial, which wouldn't start until late next year at the earliest.

Bonds' defense team is expected to attack the credibility of the witnesses, who include Bonds' former mistress and a onetime business partner who had a bitter split with the slugger over memorabilia sales. Legal experts say the reliability of the drug test, seized during a raid of the BALCO steroids lab, also will be subject to fierce scrutiny by Bonds' lawyers.

The 10-page indictment mainly consists of excerpts from Bonds' December 2003 testimony before a grand jury investigating the Bay Area Laboratory Co-Operative, or Balco. It cites 19 occasions in which Bonds allegedly lied under oath.