Correction: The original version of this story reported the wrong age for Mr. Gwirtzman at the time of his death. He was 78.

Milton S. Gwirtzman, a Washington lawyer and political consultant who was best known as a confidant to John, Robert and Edward Kennedy, died July 23 of metastatic melanoma at his home in Bethesda. He was 78.

Mr. Gwirtzman was fresh out of Yale Law School when he entered the political world in 1958 as a speechwriter for former president Harry S. Truman, who was traveling the country to campaign on behalf of Democrats running for Congress.

In 1960, the young lawyer joined Sen. John F. Kennedy’s successful presidential campaign as an assistant research director. Mr. Gwirtzman’s responsibilities included helping prepare Kennedy (D-Mass.) for debates against then-Vice President Richard M. Nixon, the Republican candidate.

Two years later, Mr. Gwirtzman worked on Edward M. Kennedy’s first campaign for the U.S. Senate, beginning a personal and professional association that lasted more than half a century until Ted Kennedy’s death in 2009.

Mr. Gwirtzman was one of a tight circle of advisers whom Ted Kennedy called on in times of crisis, including the 1969 accident on Chappaquiddick Island, Mass., in which Kennedy left a party and drove off a road into the water. His young companion, Mary Jo Kopechne, drowned as Kennedy swam to safety.

Kennedy tried to address the tragedy with a televised speech — a confession and apology drafted by Mr. Gwirtzman and Theodore C. Sorensen, John F. Kennedy’s former speechwriter.

Mr. Gwirtzman worked with Ted Kennedy on several of the senator’s books, including “Her Grace Above Gold,” a book of tributes to Rose Kennedy, the family matriarch. In the last years of Ted Kennedy’s life, Mr. Gwirtzman helped him prepare for oral history interviews that are housed at the University of Virginia’s Miller Center for public affairs.

In addition to his work for John and Ted Kennedy, Mr. Gwirtzman was chief speechwriter in 1964 for former U.S. Attorney General Robert F. Kennedy during his successful campaign for a U.S. Senate seat in New York.

Mr. Gwirtzman also worked for Robert Kennedy’s presidential campaign in 1968. After Robert Kennedy was assassinated that year, Mr. Gwirtzman helped draft a eulogy that was delivered by Ted Kennedy.

Mr. Gwirtzman then co-wrote — with William J. vanden Heuvel, another member of the inner Kennedy circle — a political biography of the slain candidate, “On His Own: Robert F. Kennedy, 1964-1968.”

Published in 1970, the book argued that the relationship between Kennedy and President Lyndon B. Johnson — often described in the press as a bitter rivalry — was also defined by sincere mutual respect. The authors offered examples of efforts by the two men to overcome their antagonism toward each other.

“As always in politics, the evidence of a personal conflict was considered far more newsworthy than any attempts at conciliation,” Mr. Gwirtzman told the New York Times in 1970. “The media did not create the tension and distrust between Kennedy and Johnson, but they did magnify it into something with a life of its own, beyond the acts of the two men.”

Writing in The Washington Post, political reporter Haynes Johnson critiqued “On His Own” as “a partisan book, but it is basically a fair one.”

Milton Saul Gwirtzman was born March 17, 1933, in Rochester, N.Y. He graduated from Harvard University in 1954.

His first marriage, to the former Elisabeth Lansing, ended in divorce.

Survivors include his wife of 13 years, Katherine “Kit” Krents of Bethesda; two sons from his first marriage, Matthew Gwirtzman of Brookline, Mass., and Dan Gwirtzman of New York; three stepsons, Jamie Krents of New York, William Krents of Shanghai and Michael Krents of Baltimore; and two sisters.

In addition to his work with the Kennedy family, Mr. Gwirtzman practiced law and worked as a political consultant in Washington and Boston, and lived briefly in Paris, where in the early 1970s he published a newsletter for businessmen engaged in investment in the United States.

In the late 1970s, Mr. Gwirtzman served as chairman of the National Commission on Social Security, which reviewed the country’s major entitlement programs and issued recommendations for fixes to ensure long-term viability. Some of those ideas were incorporated into Congress’s Social Security overhaul in 1983.

In 1999, Mr. Gwirtzman was a Treasury Department special adviser who helped craft a multibillion-dollar settlement between Holocaust survivors of Nazi slave labor camps and German companies that benefited from that labor. He received the Treasury Secretary’s Honor Award for that work.