Mr. Koch appeared, mostly as himself, in a score of movies, including “The Muppets Take Manhattan” and “The First Wives Club,” and in cameo roles on television shows, including “Sex and the City.”

And he was the star, of course, of “Koch,” the documentary film by Neil Barsky that had its premiere on Tuesday at the Museum of Modern Art. Mr. Koch, hospitalized, was forced to miss the event.

For years Mr. Koch worked out with a personal trainer almost every morning at a gym. He became a partner with Robinson, Silverman, Pearce, Aronsohn & Berman, which in a 2002 merger became Bryan Cave, an international law firm and one of the largest real estate practices in New York. He provided advice and brought in many clients.

He became an adjunct professor at New York University, Brandeis University and Baruch College of the City University of New York, and gave lectures across the country and abroad, with minimum fees of $20,000 for off-the-cuff talks on race relations, drugs, anti-Semitism or “Koch on the City,” “Koch on the State” or “Koch on Everything.”

From 1997 to 1999, he was the judge on the nationally syndicated show “The People’s Court,” hearing small claims and ribald testimony like that of a man who claimed he suffered whiplash from a topless dancer’s breasts. Mr. Koch was done in by the competing “Judge Judy” — Judith A. Sheindlin, a retired New York City Family Court judge — and was replaced by her husband, Gerald Sheindlin, a retired State Supreme Court justice. Mr. Koch had appointed both to the bench.

He wrote more books — 17 in all — murder mysteries, commentaries on politics, and other subjects. Most were a blend of his insights, experiences and observations with co-authors providing the workaday prose. In office, he produced “Mayor” (1984), “Politics” (1985) and “His Eminence and Hizzoner” (1989). Later came “All the Best: Letters From a Feisty Mayor” (1990), “Ed Koch on Everything” (1994), “I’m Not Done Yet” (2000) and “Buzz: How to Create It and Win With It” (2007).

Mr. Koch and his sister, Pat Koch Thaler, wrote “Eddie: Harold’s Little Brother,” a children’s book that appeared in 2004. His brother, Harold M. Koch, a carpet distributor, died in 1995. Besides his sister, a former dean at N.Y.U. whom he saw regularly in later years, Mr. Koch is survived by New York itself, as an old friend put it a few years ago.

“The city was and is his family,” said Maureen Connelly, a former press secretary and veteran political adviser. “We used to be scared about what would happen to Ed if he lost. We said it would be best if he just died in the saddle. But he never had any intention of getting off the horse.”