The city Department of Transportation is trying to fire a worker for being crazy — because he sings too much on the job.

The agency veteran had been happily belting out tunes at work for 33 years, until a new boss ordered him to have his head examined last year following a confrontation over the crooning, according to city documents.

Longtime colleagues say the golden-throated worker — identified only as “M.S.,” who oversees Staten Island’s highway markings — and his tunes had never drawn complaints.

But a new chief of staff appointed in March claims she received a number of complaints and twice asked him to keep the volume down.

When M.S.’s crooning wafted into a workplace meeting a few days later, his bosses confronted him — and he snapped back that they were the reason he is taking meds. He then pulled a pill bottle out of his pocket.

The higher-ups reported M.S. to the agency, saying he “needs help” based on his “strange actions and behaviors,” and investigators followed up with a report recommending he be placed on leave due to the singing, the blowup and an unsubstantiated report of reckless driving.

He was also sent to a psychiatrist, Dr. David Salvage, who testified that M.S. is “psychotic” and displays “extreme narcissistic entitlement.”

But an administrative-law judge this month dismissed the case following a hearing — blasting the city and Salvage for presenting a shoddy case that didn’t stand up in court.

“Dr. Salvage embellished his descriptions to enhance the persuasiveness of his report,” Judge Joycelyn McGeachy-Kuls wrote.

“Significant aspects of the [city report were] . . . not corroborated by any witness testimony or [were] rebutted by credible eyewitness testimony.”

McGeachy-Kuls sided with M.S.’s own longtime doctor, who says M.S. has been taking meds for depression since two of his kids were diagnosed as autistic in 2006, but it doesn’t affect his work.

Salvage’s assessment, partially based on the city report, was full of “subjectivity and illogic,” the judge said. In once instance, he quizzed M.S. on what he would ask for if granted three wishes — then bizarrely denounced the dad’s desire to “hear his non-verbal autistic son speak” as unrealistic, she noted.

M.S. hasn’t sung a note at work since the saga began, she wrote.

The Department of Transportation said it is reviewing the decision.