A judge refused on Friday to dismiss corruption charges against Assemblyman Sheldon Silver, whose lawyers had argued that Preet Bharara, the United States attorney in Manhattan, had made improper statements that deprived their client of the presumption of innocence.

But the judge, Valerie E. Caproni of Federal District Court, said she did not “condone the government’s brinksmanship relative to the defendant’s fair trial rights, or the media blitz orchestrated by the U.S. attorney’s office” in the days after the arrest of Mr. Silver, the former State Assembly speaker.

She cited a news conference held by Mr. Bharara on the day of the arrest in January, and a series of posts on Twitter from his office citing his comments and a previously scheduled speech he gave the next day in which he condemned Albany’s culture of corruption.

“In this case,” the judge wrote, “the U.S. attorney, while castigating politicians in Albany for playing fast and loose with the ethical rules that govern their conduct, strayed so close to the edge of the rules governing his own conduct that defendant Sheldon Silver has a non-frivolous argument that he fell over the edge to the defendant’s prejudice.”