Robert M. Morgenthau, a courtly Knickerbocker patrician who waged war on crime for more than four decades as the chief federal prosecutor for Southern New York State and as Manhattan’s longest-serving district attorney, died on Sunday in Manhattan. He was 99.

Mr. Morgenthau’s wife, Lucinda Franks, said he died at Lenox Hill Hospital after a short illness.

In an era of notorious Wall Street chicanery and often dangerous streets, Mr. Morgenthau was the bane of mobsters, crooked politicians and corporate greed; a public avenger to killers, rapists and drug dealers; and a confidant of mayors and governors, who came and went while he stayed on — for nearly nine years in the 1960s as the United States attorney for the Southern District of New York and for 35 more as Gotham’s aristocratic Mr. District Attorney.

For a Morgenthau — the scion of a family steeped in wealth, privilege and public service — he was strangely awkward, a wooden speaker who seemed painfully shy on the stump. His grandfather had been an ambassador in President Woodrow Wilson’s day, and his father was President Franklin D. Roosevelt’s treasury secretary. His own early political forays, two runs for governor of New York, ended disastrously.