The police union won an emergency court order Wednesday blocking the mayor and the NYPD commissioner from posting summaries of police disciplinary records online — after arguing that the “illegal” move would endanger cops.

The department had planned to start releasing information about cops accused of misconduct as early as April 16, according to the Manhattan Supreme Court suit filed by the Patrolmen’s Benevolent Association.

“The demand for ‘transparency’ doesn’t trump the law or the safety of New York City police officers,” PBA president Patrick Lynch said.

The disclosures would omit cops’ names but would include their rank, time on the job, prior disciplinary issues, departmental trial information and any penalties imposed, the suit says.

The PBA argues that the redacted summaries would not prevent people from identifying the officers in question as witnesses may recognize the cops and the summaries could be cross-referenced with public civilian complaints.

The PBA further argues that the postings would be illegal under a controversial 1976 state law called 50-a that makes all police personnel files private.

Critics say the law prevents accountability, while supporters counter that it’s necessary to protect officers from harassment.

The mayor and police commissioner believe they can bypass that statute by summarizing or redacting portions of the records. But the PBA says the state’s highest court deemed that type of workaround “illegal” as recently as last year.

“In addition to being plainly illegal, [their] conduct has real-life consequences for the more than 24,000 New York City police officers the PBA represents,” the suit says, citing a recent botched plot to kill a cop with a mail bomb.

“The public release of the disciplinary record summaries endangers the life or safety of … police officer[s],” the suit says.

Manhattan Supreme Court Judge Arthur Engoron stopped disclosures pending a June hearing on the dispute.

Reps for the NYPD and the city did not immediately return requests for comment on the suit.