Ed Koch, the outspoken former mayor of New York City, who famously refused to discuss his sexuality with reporters, has died of congestive heart failure aged 88.

New York Mayor Michael Bloomberg said the city had “lost an irrepressible icon, our most charismatic cheerleader” and announced that flags at all city buildings would fly at half mast.

Koch was a lifelong bachelor, and his sexuality became an issue in the 1977 New York mayoral election when homophobic posters urged for New Yorkers to vote for his rival Andrew Cuomo. They read:  “Vote for Cuomo, Not the Homo.”

The Democrat, who served three mayoral terms throughout the 1980s, was recently seen in the Oscar-nominated HIV/AIDS documentary How to Survive A Plague.

The film featured activist Spencer Cox, who died late year at the age of 44, and also included members of the organisation he co-founded TAG (Treatment Action Group).

At the beginning of the AIDS epidemic, Koch found himself under fire for controversially siding with the New York Health Department in choosing to shut down the city’s gay bathhouses in 1985.

Playwright and AIDS activist Larry Kramer criticised Koch for not doing more to stop the spread of AIDS in New York. “He was a closeted gay man, and he did not want in any way to be associated with this,” Kramer declared to New York magazine.

In response, Koch replied: “Listen, there’s no question that some New Yorkers think I’m gay, and voted for me nevertheless. The vast majority don’t care, and others don’t think I am. And I don’t give a **** either way!”

The former mayor recorded a video in support of marriage equality for the Human Rights Campaign in 2011.