This is a lot of court drama — even for a team called the Judges.

A legendary Queens high school basketball coach has gotten caught up in a legal battle with the city over alleged recruiting violations — which led to his suspension as he was just a few victories away from becoming the winningest hoops coach in New York City history.

Coach Ron Naclerio, 68, went to court in December to win his right to continue leading the Benjamin N. Cardozo High School Judges — so named in honor of the school famous jurist namesake — and continue on his quest to top the current city coaching wins record of 972. He is just 2 wins away from tying it.

Legendary Cardozo High School basketball coach Ron Naclerio, 68, has gotten caught up in a legal battle with the city over alleged recruiting violations. J.C. Rice

The scrappy Bayside native’s bid for history was briefly derailed last month, when city investigators accused him of improperly recruiting students from other schools to join his team, according to court records reviewed by The Post.

The allegations against Naclerio, who has coached at Cardozo for 51 years, led to his suspension on Dec. 3.

The Judge’s coach then went before a real-life jurist in Queens state court, and secured a restraining order allowing him to rejoin the team as the case raged on.

When the coach texted Cardozo principal Meagan Colby on the morning of the game to report what he called the “good news” of the ruling, Colby replied that she was not yet aware of it.

Naclerio then responded with a copy of the court order, adding: “My understanding is that a violation of a court order by you or any other official would have serious consequences, so I trust you will abide by its explicit terms and seek your own legal advice.”

Despite the legal win, the saga took an ugly turn during a Dec. 6 away game at John Bowne High School in Kew Gardens Hills, when school security guards escorted Naclerio out of the gym in full view of both teams, parents and fans, court papers reveal.

Naclerio is 2 wins away from tying the city record of 972 for most coaching wins amongst all high school basketball coaches across the Big Apple. Stephen Yang

The veteran coach — known for pacing up and down the sidelines in an orange polo and blue pants — was “surrounded” by security after arriving at the game and forced to stay in an adjacent room while his Judges prevailed over John Bowne, 65-52, his lawyer wrote in court papers.

On Friday, Naclerio received a letter from Cardozo brass saying that they’ve decided his punishment should be a two-game suspension — which would include the Dec. 6 game and another game he missed retroactively. He would also be allowed to stay on as coach, but the ruling would still stay on his record as a dark mark. 

“This conduct is unacceptable and represents a serious lapse in professional judgment,” Principal Colby wrote in the letter laying out the punishment.

Naclerio denies any wrongdoing — and his attorney said he was considering what his legal options are going forward to clear his name.

“At this point in Ron’s career, parents and players —  they recruit him. He doesn’t recruit,” his lawyer Thomas Rome told The Post, about the recruiting violation claims.

Naclerio’s quest for the record was briefly halted last month after he was suspended on Dec. 3, following rumors of the legendary coach of 51 years improperly recruiting students to join his program. X/@DozoHoops

“On the facts, he has completely rebutted every single allegation, but the principal came to a different conclusion for reasons that I think have nothing to do with the testimony and the rebuttal, but for other reasons,” he added, calling the accusations “made up.”

A city investigator concluded on Nov. 26 that Naclerio, who is also a substitute teacher at Cardozo, had breached city rules saying city employees cannot “recruit, encourage, or entice a student-athlete to transfer from one high school to another high school for athletic purposes,” court papers say.

Several players interviewed as part of the probe said that Naclerio had recruited them after seeing them play at other schools or nearly tournaments in city parks, the DOE probe claimed.

One 17-year-old junior said that he goes to other high schools to recruit players for Cordozo, the investigator wrote.

The anonymous complainant who had reported Naclerio had alleged that “most of the team is comprised of students who transferred during their junior or senior year,” the DOE prober said.

Naclerio downplayed the seriousness of the recruiting probe in a brief interview Friday afternoon, hours before his team was set to tip off in a home game against Forest Hills, where he was seeking win no.971.

“I’m in my second half century [of coaching], 51 years, you know. You have plenty of highs and you have plenty of lows,” he told The Post over the phone.

“It was two people [that] made an anonymous phone call,” he said of the origin of the recruiting investigation. “And of course….they have to look into it.”

“You know, the rest is history,” he added. “I mean, I am back coaching, you know, which is good.”

Start your day with all you need to know

Morning Report delivers the latest news, videos, photos and more.

Thanks for signing up!

Naclerio has won two city titles — 1999 and 2014 — and has produced four NBA players — Rafer Alston, Royal Ivey, Duane Causwell and James Southerland — while coaching and training numerous others such as Metta World Peace, Elton Brand and Joakim Noah.

The coach is currently chasing Jack Curran, former coach at Archbishop Molloy High School in Queens, who holds the record for the most wins in New York City high school history, with 972.

Naclerio is seeking history on Martin Luther King Weekend decades after his father Emil Naclerio, a thoracic surgeon at Harlem Hospital, spent over two hours in surgery saving the life of Martin Luther King Jr. after he was stabbed by a deranged assailant in 1958.