In 1971 Walter Matthau played a lovable old geezer in a movie called “Kotch,” but if Neal Barsky is to be believed, that character had nothing on Ed Koch, the three-term mayor of New York profiled in this affectionate documentary. Barsky doesn’t totally ignore the tribulations of Koch’s time in office—or his serious self-inflicted political wounds—but generally underplays them in favor of an overall favorable portrait, and finds the elderly Koch’s curmudgeonly attitude a source of bemused admiration.

Koch came to power at a difficult time in the city’s history, of course—he won in a crowded field at a time of fiscal uncertainty, shortly after a citywide blackout and the rampage of the serial killer called the Son of Sam—and he proved a different kind of Democrat, not just sharp-tongued but conservative in fiscal matters while broadly liberal on social ones (though not sufficiently so for some segments of the traditional Democratic constituency). In some ways he was an early example of the “new Democratic” species that would come to the fore in the Clinton years. But his endless self-confidence, his puckish spirit and his familiar air (“How’m I doin?” he kept shouting to folks on the street) made him a pleasant change for a while, and though he antagonized some core groups in his first term (particularly by closing Harlem’s Sydenham Hospital, which he had earlier pledged to keep open), he coasted to a second term in 1981 and won again in 1985, after stumbling in a run for governor in 1982.

It was during Koch’s third term that he found himself buffeted by scandals in which he protested he wasn’t involved but which tarnished him anyway (while burnishing the reputation of prosecutor Rudy Giuliani), and the film shows him suffering public outrage as a result. Barsky also gives substantial space to the mayor’s inadequate response to the AIDS crisis, which was thought especially odd because of persistent rumors that he was gay himself—something he had confronted during his first campaign against Mario Cuomo by a very public relationship with erstwhile Miss America Bess Myerson (though later saying merely that his sexuality was nobody’s business but his own). Those problems, combined with his deteriorating relationship with the African-American community, exacerbated by his frequently ill-thought off-the cuff remarks, prepared the way for his inevitable exit from the New York City political scene.

Observations from journalists and others are included offer assessments about Koch’s tenure in office, many mildly critical but generally tolerant toward a colorful character who made a newsman’s job easier. And certainly Barsky seems charmed by the octogenarian Koch, whom he interviews at length, easily extracting provocative remarks about the past and the present, and follows around on his more recent peregrinations. The brashness that made him a larger-than-life character in the eighties is still there, and the film exults in it. So too are the remnants of old battles: when it’s proposed to rename the Queensboro Bridge after him, several African-American councilman strenuously object. But when the deed is done, Koch accepts the honor with commendable grace, quoting from “The Great Gatsby,” no less, in his brief remarks. (Koch lived to see the finished documentary; he died early this year at age 88.)

“Koch” is obviously a selective piece of work, and it arguably goes a mite easy on its subject. But it offers an engaging if incomplete portrait of an unconventional politician who, for better or worse, was the controversial standard-bearer of a great city during a time of turmoil, tension and enormous social and political change.