New York State’s highest court has tossed out a murder indictment against a man who sat on Rikers Island for more than six years awaiting trial, ruling the delay was caused by the Manhattan district attorney’s office, which kept him locked up as it struggled to bolster its case against him.

In its split decision on Thursday, the New York Court of Appeals wrote in unusually pointed language that “incarceration should generally follow conviction, not precede it.” The court’s decision, which cited the defendant’s constitutional right to a speedy trial, was issued less than a month after a federal appeals court in New York vacated a marijuana distribution charge against a man from Cattaraugus, N.Y., who spent seven years in jail and never went to trial.

The state court’s 4-to-3 ruling came in the case of Reginald Wiggins, who was charged in May 2008 with fatally shooting a 15-year-old boy at a Sweet 16 party on West 90th Street in Manhattan. Mr. Wiggins, who was 16 at the time, was denied bail and was sent to Rikers Island, where he was locked up for years as Manhattan prosecutors tried to get his co-defendant in the shooting, Jamal Armstead, to testify against him.

Mr. Armstead had also been charged with murder, accused by the prosecutors of trying to take the first shot at the victim and handing the gun to Mr. Wiggins when it failed to fire. Even though Mr. Armstead “repeatedly indicated through his lawyer that he would never testify against” Mr. Wiggins, the ruling said, prosecutors spent two-and-a-half years — from January 2009 to June 2011 — trying to secure his cooperation.