NEW YORK (AP) — The rapper Tekashi 6ix9ine was sentenced to two years in prison Wednesday by a judge who said his extraordinary cooperation with prosecutors let him dodge potential decades in prison but did not absolve him entirely for using a violent gang as his “personal hit squad.”

The 23-year-old performer, whose real name is Daniel Hernandez, could have faced a mandatory minimum 37 years in prison for crimes that included orchestrating a shooting in which an innocent bystander was wounded.

In addition to the drastically reduced prison sentence, U.S. District Judge Paul A. Engelmayer also fined him $35,000 and ordered him to perform 300 hours of community service after he pleaded guilty earlier this year to charges accusing him of joining and directing violence by the gang known as Nine Trey Gangsta Bloods.

Tekashi 6ix9ine has already served 13 months and will be released in late 2020.

The three-hour sentencing proceeding Wednesday included plenty of drama, including a moment where the rapper seemed visibly shaken to see his natural father, someone he hasn’t been in contact with since age 9, among the spectators in the courtroom. When the father later stood up and tried to address the judge, Tekashi 6ix9ine did not turn around to look at his father. His lawyer and a prosecutor agreed the man should not speak.

A woman who identified herself only as L.L. sobbed as she blamed the rapper for the day she was shot in the foot. She demanded an apology and Tekashi 6ix9ine obliged, saying he would pay her medical bills.

After his arrest, Tekashi 6ix9ine 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.

Engelmayer said he found some of internet memes during the trial funny, even when they were at the expense of Tekashi 6ix9ine and himself, but he harshly criticized those who mocked Tekashi 6ix9ine’s cooperation.

“Your cooperation was impressive. It was game changing. It was complete and it was brave,” the judge said.

But the judge said the amount of time the rapper has already 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.

The judge said there was no reason for it since Tekashi 6ix9ine had achieved commercial success and fame before he decided to “join the gang and use it as your personal hit squad.”

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 made a lot of bad choices in life, but that does not make me a bad person,” he said in a lengthy letter he read in court.

He shared 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.

Assistant U.S. Attorney Michael Longyear said the rapper’s cooperation was “not only substantial, it was extraordinary.” He said Tekashi 6ix9ine began talking freely about the gang’s activities when the FBI offered him protection the day before he was arrested. The rapper met with authorities nearly two dozen times.

“He was truthful. He was forthcoming. He was an open book,” Longyear said. The prosecutor said it enabled the government to charge additional gang members and his testimony helped convict the gang’s leaders.

Longyear said it was even more remarkable given the danger that he and his family will face as a result.

“Forever, in the government’s view, he will have to look over his shoulder,” Longyear said.

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.

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.”

Last year, he 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.

The judge noted that Tekashi 6ix9ine’s incarceration does not seem to have harmed his rap career and marketability, proving the worn adage that “no publicity is bad publicity.”

Still, he warned him not to commit any more crimes.

“America loves a comeback, but there are probably limits to that,” he said.

Copyright 2020 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.