A uniformed NYPD sergeant was caught on video unleashing a vulgar tirade against a group of Brooklyn men — threatening them with his gun even while condoning their criminal behavior, The Post has learned.

Sgt. Lesly Charles even indicated that some criminal activity is apparently OK on his beat — as long as he’s paid proper respect.

“You guys are hustling or whatever, I ain’t got no problem with that. Listen . . . do your thing,” Charles barked during the April 28 diatribe, which is now being investigated by the city’s Civilian Complaint Review Board. “But when I come around and I speak, you f–king listen. Tell your boys.”

The surly sergeant apparently was angry over a car that was illegally parked on Ditmas Avenue in the Kensington section.

His rant against the men was recorded on a 20-minute cellphone video obtained exclusively by The Post.

The footage includes Charles berating a young man in the roadway near a silver BMW, telling him: “This is my street. All right? If you got to play tough, that’s your problem . . . I do whatever the f–k I want.”

A short time later, Charles followed the group into the nearby No. 1 Chinese Food restaurant, flanked by two plainclothes cops.

“I have the long d–k. You don’t,” the cop bragged.

“Your pretty face — I like it very much. My d–k will go in your mouth and come out your ear. Don’t f–k with me. All right?”

After the target of his tirade insisted, “I didn’t do anything,” Charles retorted, “Listen to me. When you see me, you look the other way. Tell your boys, I don’t f–k around. All right?”

“I’ll take my gun and put it up your a– and then I’ll call your mother afterwards. You understand that?”

For good measure, the sergeant added: “And I’ll put your s–t in your own mouth.”

Charles added, “I’m here every f–king day. I don’t go home. I have no life. No kids. I do what I do.’’

The 21-year-old man who shot the video — and provided it to The Post on the condition of anonymity — was arrested that night and charged with disorderly conduct, which court records show was for ignoring the cops’ orders to leave.

Police sources said he has been arrested more than 20 times, including for petit larceny and weapons and pot possession.

An NYPD spokeswoman said the department is investigating the incident.

The man’s lawyer, David Zelman, said it was troubling that “there were other cops by [Charles’] side, and they seemed to take it in stride.”

Charles, reached at home yesterday, said, “I’m just doing God’s work. You know I can’t comment . . . Have a blessed day.”

A source close to the sergeant said that in the past, “all efforts at civility failed’’ in dealing with the men. They are known to loiter and play loud music, prompting complaints from local businesses, law-enforcement sources said.

“The sergeant was trying to get the message across in a way they could understand,’’ the source said.

Additional reporting by Reuven Fenton