Ed Koch, the former New York City Mayor who took the city back from the financial brink before presiding over its crack epidemic and AIDS crisis, died of congestive heart failure early this morning. He was 88.

Koch successfully navigated the city to financial health, a major accomplishment, and helped ease New York's housing predicament. But his mayoralty was also marked by corruption, and the city he presided over was one suffering deeply from homelessness, the crack epidemic, and fraught racial relations that his blunt style, and abusive police force, did little to assuage. Widely understood to be a closeted gay man, Koch's inaction during the early stages of the AIDS crisis earned him the eternal enmity of the activists in the ACT UP crew, and the playwright Larry Kramer, who called Koch an "evil man."

But he's best remembered by people who came to the city after his tenure as a character: a combative, funny, movie-reviewing crank, a New Yorker's New Yorker. If nothing else this is a tribute to his charisma, though it also tells us something about the odd and inevitable nostalgia current New York has for its mythically "gritty" past.

This is a photo of Koch with Diana Ross:

Koch, the son of Jewish immigrants from Poland, was born in the Bronx in 1924. After a stint in the Army during and just after World War II (Koch helped de-Nazify Bavaria after V-Day), Koch got a law degree and spent two decades in private practice in the city; in 1963, Koch ran for, and won, his first office: district leader of Greenwich Village, a position from which he ousted Democratic power broker Carmine De Sapio. From there, he jumped to City Council; from there, to Congress, where he earned a reputation as a reliable anti-war liberal.

Koch stayed in Congress for eight years. In 1977, he ran for Mayor of New York City in a crowded Democratic field that included the incumbent, Abe Beame, and future governor Mario Cuomo. The city had been left in near bankruptcy by Beame's predecessor John Lindsay and Beame was widely disliked; Koch, calling himself a "liberal with sanity," ran as an efficient, competent manager who could steer New York back to prosperity and reduce crime. He supported the death penalty, bashed welfare, and made a campaign promise to eliminate the Board of Education.

One problem with the image he was trying to craft: Koch was single, and gay. Koch never come out of the closet, and generally refused to answer questions about his sexuality (once, though only once, he described himself as "heterosexual" publicly), but even in the late 1970s it was widely understood: "VOTE FOR CUOMO, NOT THE HOMO," read an unofficial Cuomo placard. (In response, Koch began to step out with Bess Myerson, a close friend and former Miss America.)

Rumors aside, Koch's rightward turn worked. He beat Cuomo by a percentage point in the primary, and by a wider margin in the runoff, before going on to take the general election. Once in office, Koch laid off 10 percent of the city's staff, cut services, settled with unions, went after patronage and took out billions of dollars in loans. It worked: the city began to recover.

This is a photo of Koch with Ronald Reagan:

Koch won a second term easily, and after an embarrassing failure in the 1982 gubernatorial race, settled in to a rocky decade. Homelessness and crime increased, driven in part by the crack epidemic, and AIDS, new and not entirely understood, was leading to hundreds, then thousands, of deaths. Koch did little to stop the rise of crack cocaine, and his police force was implicated in a series of brutal incidents, exacerbating his tense relationship with the black community, which had been difficult since he closed Harlem's Sydenham Hospital in his first term (a decision for which he later expressed regret).

His relationship to New York African-Americans was sunny compared with his legacy among AIDS activists and many New York gay men. Though he'd been gay-friendly as mayor, he took almost no action against the burgeoning epidemic, which was claiming thousands of lives in New York City alone. Many blamed his neglect on his fear of acknowledging his own sexual orientation. Years later, Larry Kramer was still deeply angry:

We must never forget that this man was an active participant in helping us to die, in murdering us. Call it what you will, that is what Edward Koch was, a murderer of his very own people. There is no way to avoid knowing that now. The facts have long since been there staring us in the face. If we don't see them, then we are as complicit as he.

In 1989, Koch was defeated in the Democratic primary by David Dinkins, the Manhattan borough president, who went on to become New York's first black mayor. (Dinkins served only one term, and was defeated by a Koch-endorsed Rudy Guiliani in 1993.) His longtime slogan — "How'm I doing?" — was retired, and Koch settled into a post-office life of party-crossing endorsements and TV cameos. In the late 1990s he spent a few years as a judge on the People's Court.

He seemed to mellow somewhat, even if he still endorsed George W. Bush in 2004, and threatened to withdraw support of Barack Obama in 2012. He responded to all of his email, which he printed out and annotated by hand. And he reviewed movies, for an online TV show, wearing a permanent smile — the kind the Village Voice described in 1965 as "the smile of a man disengaged from the universe":

"Do you concede?" the interviewer persisted.

"Frankly, yes," DeSapio answered.

Tumult filled the clubhouse. Exhausted campaign workers embraced; others shouted and shouted. People swirled around Koch. He had the smile of a man disengaged from the universe.

It was the night the nice guy finished first.

[image via AP]