Rapper Tekashi 6ix9ine was sentenced to two years in prison Wednesday for his ties with a street gang that fueled his rise to fame. He was spared a harsher possible sentence thanks to his decision to become a star witness for prosecutors.

The 23-year-old rapper, whose real name is Daniel Hernandez, could have been sent to prison for decades over crimes that included orchestrating a shooting in which an innocent bystander was wounded. He pleaded guilty earlier this year to charges accusing him of joining the gang known as Nine Trey Gangsta Bloods.

He has already served 13 months and will be released in late 2020.

Get Breaking News Delivered to Your Inbox

After his arrest, he shed the outlaw reputation he'd curated online and testified against his gang mates earlier this year, causing some to label him a "snitch." The testimony helped get the convictions of two high-ranking Nine Trey Gangsta Bloods members.

"Your cooperation was impressive. It was game-changing. It was complete and it was brave," said U.S. District Judge Paul Engelmayer as he announced the sentence, which is far lower than federal guidelines for the crimes, in a Manhattan courtroom.

But the judge said the amount of time the rapper has spent in prison was not enough for the violence of his crimes. He noted that many artists sing about organized crime, citing Bruce Springsteen's "Murder Incorporated."

"You, Mr. Hernandez, essentially joined Murder Incorporated," Englemayer said.

Prior to his sentencing Wednesday, Tekashi 6ix9ine expressed regret for joining the gang, apologizing to his family, his fans and the victims in the case.

"I'm not a victim. I put myself in this position from Day One," Tekashi 6ix9ine said, breaking down shortly after when he spotted his biological father whom he says he hasn't seen since the third grade in the courtroom.

He then read from a lengthy letter, saying, "I made a lot of bad choices in life, but that does not make me a bad person."

Tekashi 6ix9ine, real name Daniel Hernandez, arrives for his arraignment on assault charges on August 22, 2018, in Houston. Bob Levey / Getty

He expressed similar remorse for his actions in a letter he wrote last week to Engelmayer, discussing the relief he felt when he was arrested and his plan to make amends by warning others not to follow in his path.

"I'm happy that the public was able to witness me dealing with the consequences of my actions because I feel like it sheds a light on what can come from gang affiliation," he wrote.

In a pre-sentencing letter to the judge, prosecutors said his "cooperation was extraordinary" and was "both incredibly significant and extremely useful," enabling them to charge additional individuals. His February 1 guilty plea prompted nearly all of the other defendants to begin plea negotiations, prosecutors said.

"The government believes that his cooperation was not only substantial, it was extraordinary," Assistant U.S. Attorney Michael Longyear said at the hearing Wednesday, noting the risks Hernandez and his family faced for his testimony.

Prosecutors have described Nine Trey as one of the most violent outgrowths of United Bloods Nation, with members throughout the country. Tekashi 6ix9ine relocated his family before his cooperation became publicly known and then he was moved to a different prison facility and a unit with no gang members, the government said.

His cooperation might make him eligible for a witness protection program, though his distinctive facial tattoos — including a large "69" on his forehead — could make concealing his identity challenging.

"There is no question that the defendant's life will never be the same because of his cooperation in this case. He and his family will have to take extra safety precautions when being in public so as to avoid potential reprisals from others," prosecutors wrote in the letter.

In September testimony, Tekashi 6ix9ine told jurors his role in Nine Trey was to "just keep making hits and be the financial support for the gang ... so they could buy guns and stuff like that." Asked what he got in return, he responded: "My career. I got the street credibility. The videos, the music, the protection - all of the above."

In October of last year, the rapper was given four years probation stemming from a 2015 arrest on charges of using a child in a sexual performance. He was required to complete 1,000 hours of community service.

He was arrested in May 2015 after a video surfaced of him engaging in sexual acts with a young girl at a party in Harlem. He was 18 years old at the time.

Last year, the rapper, who also goes by Tekashi 69, had a multiplatinum hit song, "Fefe," with Nicki Minaj, which peaked at No. 3 on the pop charts, and "Stoopid," featuring imprisoned rapper Bobby Shmurda.

Tekashi 6ix9ine was repeatedly trolled during the trial by rappers like The Game and Snoop Dogg, who wrote on Instagram that he was a sellout compared to his friend Martha Stewart, who once served a five-month prison for lying about a stock sale.

Justin Carissimo and Andrea Park contributed to this report.