Exclusive Details

8:50 PM PT -- NYPD's been able to speak to witnesses and sort out what happened. The retired cop was working security for the 10k Projects exec who was meeting with Tekashi, and our law enforcement sources say everything went to hell when the exec turned away Tekashi's entourage.

We're told Tekashi and his family were taken back to their vehicle, but his entourage went back to the restaurant and confronted the exec ... who's security quickly stepped up. We're told someone in Tekashi's crew grabbed a chair and smashed it over the exec's bodyguard, who then took out his gun and fired.

As we told you ... 6ix9ine's guy was shot in the abdomen.

5:10 PM PT -- We've learned the bodyguard is now out of surgery and in stable condition.

4:45 PM PT -- The shooter didn't get away scot-free. Law enforcement sources tell us a retired police officer was nearby when the gunfire broke out and shot at the suspect, who cops believe he was hit.

We're told NYPD is searching for the perp.

Gunfire erupted during Tekashi69's celebration after his court hearing, and one of his bodyguards was hit ... TMZ has learned.

Law enforcement sources tell us, the group was at a restaurant in midtown NYC, celebrating the fact that 6ix9ine dodged a prison sentence and got off with 4 years probation in his child sex case.

Here's what we're told -- Tekashi was meeting a 10k Projects Records exec at the party. A bodyguard for the exec turned away 6ix9ine's entourage, saying the only person who could come into the restaurant was Tekashi himself. Tekashi's security said hell no, and an argument erupted.

During the argument, a third party walked up and fired 4 shots, hitting Tekashi's bodyguard in the stomach. The bodyguard was taken to the hospital.

We're told Tekashi was not involved in the scuffle. Nevertheless, it's interesting just hours before the shooting, the judge warned the rapper to stay out of trouble or risk going to prison.

The Shade Room was first to break the story.