In the late 1970s when Edward I. Koch won his first term as mayor of New York, the city was in shambles, its coffers and confidence sapped by financial crises and a paralyzing blackout. It needed a fighter and found one in Koch, a well-practiced pol with the determination — and bite — of a bulldog.

He steered the city out of bankruptcy and restored its swagger, a one-man cheerleading squad who personified the witty and feisty New Yorker.

The three-term mayor of New York and perennial civic combatant, who rallied and riled the city in and out of office with his tenacious style and irrepressible opinions, died Friday of congestive heart failure at New York-Presbyterian/Columbia Hospital, said his friend and spokesman George Arzt. He was 88.

Koch had been hospitalized Monday, a day before a documentary about him, "Koch," premiered in New York City. He had been hospitalized several times in recent months for breathing problems and other ailments.

For most of his adult life, Koch had lived alone in an apartment off Washington Square Park in Greenwich Village. It was where he departed the morning in 1978 when he rode a public bus to City Hall to be sworn in as the city's 105th mayor and where he returned 12 years later, after a disastrous fourth run to keep the job he clearly relished and worked hard at. He spent the rest of his life out of public office but rarely out of public view.

Notable deaths of 2013

He juggled almost a dozen jobs — including law partner, columnist, author, radio show host, playwright, movie reviewer and lecturer — and appeared relentlessly in the media, a shtick-artist with one of the most recognizable New York accents in the world. When he wasn't bellowing at opponents on political round tables, he was hawking such products as diet aids and soft drinks in advertisements and popping up in screen cameos as himself, the quintessential New Yorker, alongside Carrie and the girls in television episodes of "Sex and the City" or with Big Bird in the 1984 film "The Muppets Take Manhattan."

His support was pivotal in Republican Bob Turner's victory in the September 2011 special election in the heavily Democratic congressional district that had been represented by Rep. Anthony Weiner, who was forced to resign in a "sexting" scandal. "Ed Koch was enough to turn this around," Democratic strategist Hank Sheinkopf said after Turner's win.

For his 86th birthday in 2010, New York's current mayor, Michael Bloomberg, renamed the bridge linking Manhattan to Koch's home borough of Queens the Ed Koch Queensboro Bridge, saying it was, like Koch, "a resilient, hard-working New York City icon."

"He was a great mayor, a great man, and a great friend," Bloomberg said Friday in a statement. "In elected office and as a private citizen, he was our most tireless, fearless and guileless civic crusader. Through his tough, determined leadership and responsible fiscal stewardship, Ed helped lift the city out of its darkest days and set it on course for an incredible comeback."

New York Gov. Andrew Cuomo echoed the sentiment: "No New Yorker has — or likely ever will — voice their love for New York City in such a passionate and outspoken manner than Ed Koch."

"He was the epitome of New York — loud, funny, opinionated, smart," said Arzt, who was Koch's City Hall spokesman and part of an administration alumni group that lunched with him every Saturday after he left office. "Ed was very much a straight-shooter, a champion of the middle class, a moderate Democrat akin to a Harry Truman. He defied categories."

In fact, Koch loved to enrage liberals by doing and saying the unthinkable — endorsing Republican politicians such Rudolph Giuliani and George W. Bush. But Koch also held fast to many liberal values. One of his first executive orders as mayor was adding sexual preference to a citywide ban on job discrimination.

He invited controversy and enjoyed confrontation. He once wrestled an egg-throwing heckler to the floor before the police could move in.

Altogether, Koch wrote or co-authored 17 books, including eight autobiographies, two children's books and multiple mystery novels starring himself as the detective.

Koch opined freely, never mincing words: Movie tickets were too expensive; the United Nations, after an anti-Israel vote, was "made up of gangsters, cutthroats and piranhas"; a Puerto Rican mayoral rival was a "poverty pimp"; Sarah Palin was likable but "scares the hell out of me." He never lost interest in his favorite subject — himself. "How'm I doin'?" was his trademark question.

The only topics that remained off limits were his heroic service as an infantryman in World War II — he was awarded two battle stars — and his sexuality. A lifelong bachelor, he was dogged by questions about his sexuality, which he largely ignored, although he did on two occasions describe himself as heterosexual. "I ran in a total of 24 elections and won 21," he once told the New York Times. "I will not be a coward and say I am straight or I'm gay, because it's no one's business. I got where I am today not because of sexuality or gender but because people thought I was the best at what I did...."

In recent years, Koch appeared to mellow, seeking reconciliation with former rivals, but he refused to yield when it came to standards for public service. As recently as the summer of 2010, the octogenarian ginned up a campaign called "New York Uprising" to reform state government. Despite a history of heart disease that left him with two pacemakers and a degenerative spinal disorder that caused the once-strapping 6-foot-1 former mayor to be stooped in old age, he embarked in a Jeep on a campaign-style press tour around upstate New York to shame reluctant legislators in their home districts into signing a pledge to "clean up Albany."

This was shortly after Koch, ever the showman, revealed he had finalized plans for his funeral and penned his epitaph. His gravestone will declare his pride in his religion — "My father is Jewish, my mother is Jewish, I am Jewish" — and his "fierce" love of his city and country.

Edward Irving Koch was born Dec. 12, 1924, in the Bronx and spent his early years in Newark, N.J., where his family moved after his furrier father went broke during the Great Depression. Koch attended the City College of New York before being drafted into the Army; he eventually graduated from New York University's law school and joined a liberal political reform group in Greenwich Village, the Village Independent Democrats. He served as a district leader, city councilman and for 10 years represented the East Side and lower Manhattan in Congress.

The second of three children, Koch is survived by his sister, Pat Koch Thaler. A brother, Harold, died in 1995.

In 1977, he ran in a Democratic primary for mayor against six candidates, including the incumbent, Abraham Beame, and a rising Queens political star named Mario Cuomo. Nobody expected the nebbish from the liberal clubs of Greenwich Village to emerge ahead of the pack, but Koch squeaked by with promises of pragmatic solutions to save a bankrupt city.

As mayor, he persuaded Congress to give New York additional federal loan guarantees that gave him time to put the city's fiscal house in order. He balanced the budget, cut spending, negotiated new municipal labor contracts and seeded programs to rebuild neighborhoods destroyed by years of neglect and arson.

In 1981, with endorsements from both the Democratic and Republican parties, he was returned to office with 75% of the vote.

Koch's ubiquity became such a source of tension among City Hall journalists not wanting to miss a story that his press secretary eventually installed a buzzer in the room where they were stationed so she could warn them simultaneously if the mayor was on the loose.

His critics and friends agreed that one of Koch's biggest mistakes was to fall for his own media image. Such hubris led him to run for governor in 1982, wasting a year on what he later admitted was a foolish effort. Again he was up against Cuomo in a primary, but this time Koch lost.

After losing, he wrote "Mayor" (1984), a bestselling, tell-all memoir that took harsh shots at rivals and friends. In 1985, he was reelected mayor for the final time.

That third term was quickly swamped by corruption scandals and investigations involving Koch's political allies that sent some of his aides and cronies to jail. While he was never personally implicated in wrongdoing, his administration was tainted at a time when it was also facing monumental challenges associated with crack use, AIDS and homelessness.

When he sought a fourth term, he was defeated for the Democratic nomination by Manhattan Borough President David N. Dinkins, who became the city's first African American mayor.

Jonathan Soffer, a historian and author of the 2010 book "Ed Koch and the Rebuilding of New York City," said Koch's loose lips continually caused trouble. During the 1988 presidential primary, he said Jews and other supporters of Israel would be "crazy" to vote for the Rev. Jesse Jackson.

"Koch tried to say he treated everyone equally and was racially neutral," Soffer said. "But his rhetoric was perceived by some in the black community as racially biased."

When asked later how he felt when people expressed regret at his loss, he offered a classic Kochian meld of charm and chutzpah. "The people have spoken," he said, "and the people must be punished!"

In the end, Koch never stepped far from his old City Hall office.

"In many ways Ed Koch never stopped being mayor," Police Commissioner Raymond Kelly said Friday in a statement, noting that Koch constantly gave the Police Department his opinion. "I was privileged to consider him a friend, and I am grateful that I had a few more times to be with him, on Tuesday and again last night, before he finally left New York for someplace better — although he'd probably argue that's not possible."