NEW YORK (AP) — A federal prosecutor went too far in criticizing one of the state's most powerful politicians after his arrest but not so far that the indictment against him must be tossed out, a judge said Friday as she dropped the gavel on the government's handling of the arrest.

U.S. District Judge Valerie Caproni picked apart U.S. Attorney Preet Bharara's characterization of then-Assembly Speaker Sheldon Silver's January arrest, particularly comments at a news conference and in a speech he delivered a day later.

"In this case, 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," the judge wrote.

She said she could not condone the "government's brinkmanship" or the "media blitz" that prosecutors orchestrated in the days after the Democrat's arrest but also could not conclude that the actions unfairly influenced a grand jury that later indicted him.

Silver was arrested on bribery charges after prosecutors concluded he exploited his power to reap $4 million in kickbacks over a decade. He has pleaded not guilty and said he'll be vindicated.

After the judge's ruling, Silver attorneys Joel Cohen and Steven Molo said in a statement they were "pleased that the court took exception to the conduct of the United States attorney and cautioned against future use of the tactics employed against Mr. Silver."

A government spokesman declined comment. Bharara's office has said his comments weren't unusual or prejudicial.

The judge said some Bharara comments at a news conference "could reasonably have been interpreted to reflect the U.S. attorney's personal views as to Silver's character or guilt with respect to the charges."

She also attacked tweets the prosecutor's office sent after the news conference, saying there were risks that facts will be read in isolation when they are sent on a platform that limits messages to 140 characters.

In one tweet, the government said, "Bharara: Silver monetized his position as Speaker of the Assembly in two principal ways & misled the public about his outside income." In another, it said, "Bharara: Politicians are supposed to be on the ppl's payroll, not on secret retainer to wealthy special interests they do favors for."

The judge said she was "troubled" by remarks Bharara made after the arrest that seemed to bundle together unproved allegations regarding Silver with broader commentary on corruption and a lack of transparency in certain aspects of state politics. She said Bharara could have delayed the arrest until after his previously scheduled speech.

She also said she does not accept "that any prejudicial effect of otherwise improper comments is magically dispelled by sprinkling the words 'alleged' or 'allegations' liberally throughout the press conference or speech, or by inserting a disclaimer that the accused is 'innocent unless and until proven guilty' at the end of an otherwise improper press release."