The de Blasio administration will be forced to release emails between the mayor and one of his closest private advisers — a so-called “agent of the city” — after a judge sided with The Post and NY1 in a public disclosure lawsuit.

In a 13-page ruling, Manhattan Supreme Court Judge Joan Lobis rejected the administration’s argument that emails between Mayor Bill de Blasio and BerlinRosen co-founder Jonathan Rosen can be shielded from disclosure because Rosen is an informal, unpaid consultant — even though he represents private clients with interests before the city.

“Here, the mayor is seeking to apply … deliberative privilege to someone who is not part of the mayor’s office or that of any other city agency, and who has not been hired by the mayor but is merely advising him on an informal basis,” she wrote.

“Clothing informal relationships such as that of Rosen and the mayor with the inter-agency or intra-agency privilege impermissibly broadens the exception of FOIL, counter to the public interest in transparency in government,” she added, citing the Freedom of Information Law.

Lobis concluded that “correspondence between the mayor and Rosen, who has not been formally retained by the mayor or any other city agency, is not exempt from disclosure under the inter-agency or intra-agency deliberative privilege under FOIL.”

Her ruling also said de Blasio hurt his own case by saying in December — after the lawsuit was filed — that the agents of the city would lose their “deliberative privilege” going forward.

The other so-called agents are Bill Hyers and Nick Baldick at Hilltop Public Solutions; former US Ambassador to South Africa Patrick Gaspard; and AKPD partner John Del Cecato.

A spokesman for the mayor’s office said an appeal would be filed but declined further comment.