In this May 16, 2012, file photo, former New York Mayor Ed Koch (right) talks to reporters as Assemblyman Rory Lancman watches in New York. Koch, the combative politician who rescued the city from near-financial ruin during three City Hall terms, has died at age 88. Spokesman George Arzt says Koch died Friday morning of congestive heart failure. (ASSOCIATED PRESS)

NEW YORK (AP) — When Ed Koch was mayor, it seemed as if all of New York was being run by a deli counterman. Koch was funny, irritable, opinionated, often rude and prone to yelling.

And it worked, for a while at least.

With a Bronx-born combination of chutzpah and humor, Koch steered New York back from the brink of financial ruin and infused the city with new energy and optimism in the 1970s and ‘80s while racing around town, startling ordinary New Yorkers by asking, “How’m I doing?” He was usually in too much of a hurry to wait for an answer.

Koch died of congestive heart failure Friday at 88, after carefully arranging to be buried in Manhattan because, as he explained with what sounded like a love note wrapped in a zinger: “I don’t want to leave Manhattan, even when I’m gone. This is my home. The thought of having to go to New Jersey was so distressing to me.”

Tributes poured in from political allies and adversaries, some of whom were no doubt thinking more of his earlier years in City Hall, before many black leaders and liberals became fed up with what they felt were racially insensitive and needlessly combative remarks.

The Rev. Al Sharpton said in a statement that although they disagreed on many things, Koch “was never a phony or a hypocrite. He would not patronize or deceive you. He said what he meant. He meant what he said. He fought for what he believed. May he rest in peace.”

During Koch’s three terms from 1978 to 1989, he helped New York climb out of its financial crisis through tough fiscal policies and razor-sharp budget cuts, and subway service improved enormously. To much of the rest of America, the bald, paunchy Koch became the embodiment of the brash, irrepressible New Yorker.

He was quick with a quip or a putdown, and when he got excited or indignant — which was often — his voice became high-pitched. He dismissed his critics as “wackos,” feuded with Donald Trump (”piggy”) and fellow former Mayor Rudolph Giuliani (”nasty man”), lambasted the Rev. Jesse Jackson, and once reduced the head of the City Council to tears.

“You punch me, I punch back,” Koch once observed. “I do not believe it’s good for one’s self-respect to be a punching bag.”

Or, as he put it in “Mayor,” his best-selling autobiography: “I’m not the type to get ulcers. I give them.”

Koch’s favorite moment as mayor, fittingly, involved yelling. During a transit strike that brought the subways and buses to a halt in 1980, he strode down to the Brooklyn Bridge to boost the spirits of commuters who had to walk to work.

“I began to yell, ‘Walk over the bridge! Walk over the bridge! We’re not going to let these bastards bring us to our knees!’ And people began to applaud,” he recalled.

New Yorkers eventually tired of Koch.

Homelessness and AIDS soared in the 1980s, and critics charged that City Hall’s response was too little, too late. Koch’s latter years in office were also marked by scandals involving those around him and rising racial tension. In 1989, he lost a bid for a fourth term to David Dinkins, who became the city’s first black mayor.

On Friday, Dinkins called Koch “a feisty guy who would tell you what he thinks.”

“Ed was a guy to whom I could turn if I wanted a straight answer,” he told Fox 5 News.

Mayor Michael Bloomberg saluted Koch as “a civic savior for our city in desperate times,” saying “the whole city was crumbling” when Koch was elected.

“When we were down, Ed Koch picked us up. When we were worried, he gave us confidence. When someone needed a good kick in the rear, he gave it to them - and, if you remember, he enjoyed it,” Bloomberg said.

Former President Bill Clinton and former Secretary of State Hillary Rodham Clinton remembered Koch as a fierce advocate for his city and a friend “whose convictions ran deep.”

The Clintons recalled Koch as a man with a personality big enough to match the nation’s largest city. They call him a leader who “stood up for the underprivileged and underrepresented” in every corner of New York.

A lifelong bachelor who lived in Greenwich Village, Koch championed gay rights, taking on the Roman Catholic Church and scores of political leaders. His own sexual orientation was the subject of speculation and rumors. During his 1977 mayoral campaign against Mario Cuomo, posters that read “Vote for Cuomo, Not the Homo” mysteriously appeared in some neighborhoods.

Koch offered a typically blunt response to questions about his sexuality: “My answer to questions on this subject is simply, ‘F--- off.’ There have to be some private matters left.”

Koch was also proudly Jewish and an outspoken supporter of Israel.

After leaving office, he continued to offer his opinions as a political pundit, movie reviewer, food critic and judge on “The People’s Court.” Even in his 80s, he exercised regularly and worked as a lawyer.

Describing himself as “a liberal with sanity,” Koch pursued a fearlessly independent course. When President George W. Bush ran for re-election in 2004, Democrat Koch supported him and spoke at the GOP convention. He also endorsed Bloomberg’s re-election at a time when Bloomberg was a Republican.

Edward Irving Koch was born in the Bronx on Dec. 12, 1924, the second of three children of Polish immigrants. During the Depression the family lived in Newark, N.J.

The future mayor worked his way through school, checking hats, working behind a delicatessen counter and selling shoes. He attended City College of New York and served as a combat infantryman in Europe during World War II.

He received a law degree from New York University in 1948 and began his political career in Greenwich Village as a liberal Democratic reformer, beating the powerful old-school party boss Carmine DeSapio in a race for district leader.

Koch was elected to the City Council and then to Congress, serving from 1969 to 1977 as the representative from the wealthy East Side’s “Silk Stocking” district.

His politics edged to the center of the political spectrum during his years in Congress and pulled to the right on a number of issues after he became mayor.

With New York in dire financial condition in 1977, Koch defeated Mayor Abe Beame and Cuomo in the Democratic primary to win his first term in City Hall. He breezed to re-election in 1981 and 1985, winning an unprecedented three-quarters of the votes cast.

In 1982, he made a run for governor against then-Lt. Gov. Cuomo. But his bid blew up after he mouthed off about life outside the big city.

“Have you ever lived in the suburbs?” Koch told an interviewer about a possible move to Albany. “It’s sterile. It’s nothing. It’s wasting your life.” He said life in the country meant having to “drive 20 miles to buy a gingham dress or a Sears, Roebuck suit.”

It cost him the race.

Koch’s third term was beset by corruption scandals, one of which ended in the suicide of a top party boss in 1986. Also, Koch’s friend and commissioner of cultural affairs, former Miss America Bess Myerson, stepped down after being accused of trying to influence the judge in a court case involving her boyfriend.

Koch fell out with many black voters for purging anti-poverty programs and saying, among other things, that busing and racial quotas had done more to divide the races than to achieve integration. He also said Jews would be “crazy” to vote for Jackson during the civil rights leader’s 1988 presidential campaign.

Racial tensions were running high at the time because of the deaths of two young black men who were set upon by gangs of whites in 1986 and 1989.

Koch later said the simmering tensions didn’t lead to his defeat. “I was defeated because of longevity,” he said. “People get tired of you. So they decided to throw me out.”

But he also said his biggest regret as he left office was that “many people in the black community do not perceive that I was their friend.”

On Friday, Jackson said in a statement that Koch’s “leadership and legacy will never be forgotten in New York City, New York state or our nation.”

Koch wrote 10 nonfiction books, including “His Eminence and Hizzoner,” written with Cardinal John O’Connor. He also turned out four mystery novels and three children’s books.

He played himself in the movies “The Muppets Take Manhattan” and “The First Wives Club” and hosted “Saturday Night Live.” In 1989’s “Batman,” Gotham City’s mayor bore a definite resemblance to Koch.

At 83, Koch paid $20,000 for a burial plot at Trinity Church Cemetery, at the time the only graveyard in Manhattan that still had space. He had his tombstone inscribed with the last words of Daniel Pearl, the Wall Street Journal reporter beheaded by Islamic militants: “My father is Jewish, my mother is Jewish, I am Jewish.”

The funeral will be Monday at Temple Emanu-El in Manhattan. Dignitaries including New York City Mayor Michael Bloomberg and Ido Aharoni, the Israeli consul general in New York, will be among the speakers, a person familiar with the arrangements, speaking on condition of anonymity, told the AP.

Koch is survived by his sister, Pat Thaler, and many grandnieces and grandnephews.