According to his wife, Diana, he died peacefully in his sleep at their home in Washington. No cause of death was provided.
"His age just caught up with him," she told Reuters.
While he lived a life of many careers - including stints as president of the Ford Motor Co. and the World Bank, it was his work as defense secretary that will mark his place in history. McNamara served as defense chief from 1961-68, for Presidents John F. Kennedy and Lyndon Johnson.
"He's like a jackhammer," President Johnson said of McNamara, according to the New York Times. "No human being can take what he takes. He drives too hard. He is too perfect."
McNamara became a symbol of the unpopular U.S. policy in Vietnam, a war that left more than 58,000 Americans dead, so much that some called the conflict "McNamara's War." U.S. involvement in the conflict began in the early 1960s.
In his later years, McNamara wrestled with the moral implications of the Vietnam War, which sparked passionate protests domestically. He said that he deeply regretted his role in Vietnam and had doubts about U.S. policy there even as the U.S. involvement -- and the number of American deaths -- escalated.
After lobbying Congress to pass the Tonkin Gulf Resolution in 1964, which Johnson used as the equivalent of a congressional declaration of war, and a visit to Vietnam, McNamara predicted that the U.S. could intervene and that the Vietnamese would be able to stand on their own by 1965. U.S. military involvement continued until 1975.
In 1995, McNamara released his memoir "In Retrospect: The Tragedy and Lessons of Vietnam." In it, he wrote about his deep misgivings about the war beginning in 1967. At the time, despite these doubts, McNamara continued to express public confidence that the U.S. could achieve success in Southeast Asia.
"One fear [I had]," McNamara said in a 1995 NewsHour interview, "and I expressed it to President Johnson in December 1965, was that we couldn't win the war militarily. I said to him at that time -- and I quote it in the book -- there's only a one in three chance or, at best, a one in two chance to win militarily."
The book renewed the bristling debate over his role in the war. A New York Times editorial referred to McNamara as offering the war's dead only a "prime-time apology and stale tears, three decades late," according to the AP.
He repeated his misgivings in the 2003 documentary "The Fog of War: Eleven Lessons from the Life of Robert S. McNamara." The film was released during the first year of U.S. involvement in Iraq.
He was first named secretary of defense in 1961 by President Kennedy and was retained by President Johnson after Kennedy's assassination. He was the longest-serving defense secretary ever, holding the post for seven years.
In the Kennedy administration, McNamara was a key figure in both Bay of Pigs invasion of April 1961 and the Cuban missile crisis 18 months later. The crisis was the closest the world came to a nuclear confrontation between the Soviet Union and the United States.
In 1968, President Johnson removed him as defense secretary and offered him the post of World Bank president. There, McNamara worked to shift the United Nations' agency lending focus from heavy industry to farming and population control. He remained at the post for 12 years before retiring in 1981.
He went on to serve on several corporate boards and continued to push for nuclear disarmament and aid to the world's poorest countries.
Known for his fixation on statistical analysis, McNamara was known as one of Ford's "whiz kids" that helped revitalize the company. Before that, he was a professor at Harvard Business School and helped develop a new field of statistical control of supplies as a commissioned Army officer.
He was born in San Francisco on June 9, 1916 and graduated from the University of California in 1937 and received his masters from Harvard Business School.
He married fellow University of California student Margaret Craig and the two had a son and a daughter. Margaret died of cancer in 1981. He remarried in 2004 to Diana Masieri Byfield.
Editor's Note: This story has been updated from its original version.