The former police commissioner was his dapper, swaggering self yesterday as a White Plains federal judge announced he had been discharged from a prison psychiatric unit.

“He poses no risk of harm to himself or others due to any psychiatric illness,” Judge Stephen Robinson said.

The judge revealed Kerik, 54, had “voluntarily” checked into the Mental Health Forensic Unit of the Westchester County Department of Correction on Oct. 22. He underwent 10 days of testing before his return to jail yesterday.

A letter by the chief of forensics, Dr. Robert Mahler, said there were “no significant findings that would warrant ongoing admission.” The doctor cleared the ex-top cop to return to a segregated wing of the Westchester County Jail, where he is awaiting trial on corruption charges.

Kerik appeared in court in a dark suit and burgundy tie and listened quietly as the judge discussed his condition.

At the time of Kerik’s transfer to the psych unit, Robinson said Kerik was exhibiting behavior that put him “at risk.”

The judge had expressed concern after Kerik received an earlier memo from Mahler and spoke with the doctor on the phone.

The judge last month revoked Kerik’s bail and jailed him after he sent confidential legal documents to an unauthorized lawyer.

Kerik is facing trial for allegedly accepting free renovations to his co-op while serving as the city’s Correction Department commissioner in exchange for recommending a company to receive city contracts.