Tekashi69 just got a huge break -- he's getting off with probation in his child sex case.

Tekashi was tight-lipped walking into the NYC courthouse Friday to get his sentence. The judge gave him 4 years probation ... which is exactly what the rapper's team had requested. The courtroom, packed with his entourage, erupted in cheers.

Afterward, he addressed the judge directly and embraced his government name, saying he's Daniel Hernandez, not Tekashi69. He added, "I have millions of youth that look at me as a role model and the last place I want to be is incarcerated, they don’t deserve it. Thank you.”

The judge gave him credit for one year, so he effectively only has 3 years of probation left. He'll also have to perform 1,000 hours of community service, and refrain from associating with any gang members and avoid all gang activity. That part might be difficult -- he's repped the Bloods in several music videos.

Any new arrests will be deemed a violation, and he could be resentenced ... which could mean prison.

As we reported ... 6ix9ine pled guilty to one count of Use of a Child in a Sexual Performance back in October 2015, long before he was famous.

In legal docs, obtained by TMZ, prosecutors say Tekashi was at a party in Harlem where a 13-year-old girl was taped engaging in sexual acts with another man while Tekashi, 18 at the time, stood "behind the child making a thrusting motion with his pelvis and smacking on her buttocks." Prosecutors say the child is nude in the video.

The rapper's sentence was deferred for 2 years and, if he complied with certain conditions -- like getting mental health treatment and staying out of trouble -- the judge would only give him probation. The problem for Tekashi was he got arrested in Texas and Brooklyn.

As we reported ... Tekashi had filed a letter with the judge claiming his arrests for assaulting an officer (Brooklyn) and attacking a fan in a mall (Houston) don't constitute a violation of his plea deal.

Tekashi's lawyer, Lance Lazzaro, argued both arrests happened long after the Oct. 2017 deadline on his plea deal -- so 6ix9ine should only get 4 years probation and a youthful offenders program. Prosecutors had recommended he get 1 to 3 years prison time.

Score one for 6ix9ine Daniel.

His rep tells TMZ, "Daniel understands what he must now do moving forward and we will be with him every step of the way. We also want to thank the judge for being very fair and impartial."