The rapper and Instagram star Tekashi69 was sentenced to two years in prison on Wednesday by a federal judge who gave him credit for pleading guilty and helping prosecutors send several of his former gang associates in the Nine Trey Gangsta Bloods to prison.

The performer, who is also known as 6ix9ine and whose legal name is Daniel Hernandez, has already spent nearly 13 months in a federal jail and that time will count toward his sentence. Federal prosecutors in Manhattan had described his cooperation against members of the Nine Trey Gangsta Bloods as “extraordinary” and “extremely useful.”

But the judge, Paul A. Engelmayer, said the conduct Mr. Hernandez admitted to was too serious to justify his immediate release from custody, which his lawyer had sought.

“Your conduct was too violent, too sustained, too destructive, too selfish and too reckless with respect to public safety to make a sentence of 13 months at all reasonable,” the judge said, listing the litany of shootings and robberies that Mr. Hernandez, 23, had admitted to being a part of.