Police set up roadblocks on roads leading into the city and riot police backed by trucks mounted with water cannon surrounded the court complex to prevent his supporters from demonstrating.
Anwar has accused Abdullah Ahmad Badawi, the Malaysian prime minister, of orchestrating a "sham trial" to sabotage his political comeback and to deflect public attention from problems facing the ruling Barisan Nasional (BN) coalition and the country.
Abdullah denied the accusations and said the police were not so "stupid" as to charge Anwar with sodomy if they did not have sufficient evidence.
"How could I insist that he be charged?" Abdullah said late on Wednesday.
"If there is no evidence, the police are not stupid to charge [him]. It is up to them to decide."
Al Jazeera's Teymoor Nabili who was in court, said the charge under Section 377B of the penal code was significant as it meant that Anwar's accuser could also be charged with having consensual sex, unless granted immunity as a prosecution witness.
He said senior government officials had been implying that Anwar would be charged under Section 377A which provides for sexual assault, as Saiful had claimed in his police report.
Under Malaysian law, sodomy is illegal even if consensual and a conviction could see Anwar jailed up to 20 years.
There was no word on whether Saiful would also be charged.
Anwar also told Al Jazeera that the government is manufacturing the case to derail his political comeback.
"The prime minister feels very strongly that he's under siege, not only from the Malaysian public but also from his own party," he said.
The sex allegation surfaced last month as Anwar stepped up his campaign to return to parliament.
He announced plans last week to contest in an August 26 by-election his former parliamentary constituency in the northern state of Penang.
His wife, Wan Azizah Wan Ismail, president of the opposition Keadilan (Justice) party, vacated the seat to facilitate Anwar's return to mainstream politics.
Anwar is widely expected to win easily in a constituency which has been his stronghold since the early 1980s, including the nearly two decades when he was in government.
He was sacked as deputy prime minister and finance minister in 1998 and was convicted for sodomising his driver and for corruption.
The sodomy conviction was later overturned but he served six years until 2004 on the corruption charges, which barred him from office until April this year.
Anwar has said he is confident of forming the government after he gets 30 MPs from the ruling party to support his move to become prime minister in a confidence vote he wants to force next month.