Before taking up the post as Pentagon chief in 1961, Mr McNamara was the president of Ford Motor Company, turning the company around in the post World War II era.
He is most closely associated with overseeing the involvement of the US in Vietnam from 1961 to 1968.
Mr McNamara became to many anti-war critics the symbol of a failed policy that left more than 58,000 US troops dead.
Even his son, as a Stanford University student, took part in protests against the war while his father was running it.
However, in his 1995 memoirs In Retrospect: The Tragedies and Lessons of Vietnam, Mr McNamara wrote of his regret over his Vietnam role.
He described the war as "terribly wrong" owing to a combination of the anti-communist climate of the times, mistaken assumptions of foreign policy and military misjudgements.
He spoke frankly about the Vietnam war and the Cuban Missile Crisis in the 2003 documentary "The Fog of War: Eleven Lessons from the Life of Robert S. McNamara."
With the US in the first year of the war in Iraq, it became a popular and timely attraction and won an Oscar for best documentary feature.
As president of the World Bank, Mr McNamara devoted great energy into improving life in rural communities in developing countries.
He believed it was a more promising path to peace than the build-up of arms and armies.
After retiring in 1981, he championed the cause of nuclear disarmament.
Obituary: Robert McNamara
Former American secretaries of defence seldom get such widespread obituaries as Robert S McNamara.
Despite a distinguished career which saw him at the centre of power or influence at some of the most troubled times of the 20th Century, it was Errol Morris's 2003 film, The Fog of War, subtitled Eleven Lessons from the Life of Robert McNamara, which singled out this former defence secretary.
In the film, McNamara spoke frankly about the Vietnam war, the Cuban missile crisis and World War II, giving a behind-the-scenes account of the context in which important decisions were taken, in so doing raising questions about the nature of war and human behaviour.
Born in San Francisco in 1916, McNamara graduated from the University of Berkeley in economics before gaining an MBA at Harvard.
Cuban Missile Crisis
A brilliant statistician, he was drafted to help develop methods of statistical control for managing the strategic bombing campaigns against Germany and Japan.
He worked with General Curtis LeMay on the firebombing of 67 Japanese cities that killed almost a million people, 100,000 on one night in wooden Tokyo.
In The Fog of War, he agreed with LeMay's assertion that the pair "were behaving as war criminals" and would have been tried as such had their side lost.
In 1946, McNamara was hired by the Ford Motor company to rejuvenate its flagging sales. He rose to become the first president of the company outside the Ford family.
He was one of the first to introduce safety features in order to reduce the death rate in crashes.
But in 1960, he was snapped up by President John F Kennedy to become his defence secretary.
In this post, he reformed Pentagon practices, oversaw a huge military build-up and was centrally involved in the Cuban Missile Crisis of 1962, when Soviet nuclear missiles were discovered in Cuba and the world teetered on the brink of a nuclear war for 13 days.
Hate figure
In the film, he described Gen LeMay, at that time an adviser to Kennedy, and Fidel Castro, as the two most dangerous personalities of that crisis.
Gen LeMay wanted to attack Cuba unilaterally, while Mr Castro, he said, told him later that he had pressed Soviet leader Nikita Krushchev to attack the United States with nuclear weapons if the US invaded.
During the Vietnam War, McNamara supported US efforts to prevent the victory of Communist insurgents over the government of South Vietnam.
To anti-war protesters at the time, McNamara became something of a hate figure, an arrogant ultra-hawk responsible for escalating the war.
Yet recently-released tapes of conversations between McNamara and President Lyndon Johnson, used in The Fog of War, reveal Johnson chiding his defence secretary for having advised Kennedy to pull American military advisers out of Vietnam.
Instead, Johnson put ground troops into Vietnam following the Gulf of Tonkin incident in which, it was claimed, Vietnamese submarines had attacked US warships. McNamara confirmed that these attacks never actually took place.
Haunted by Vietnam
By 1966, McNamara had begun to question the wisdom of US involvement in Vietnam and, a year later, was privately advising Johnson to end the war by negotiation.
He initiated a full investigation of the American commitment to Vietnam (later released as the Pentagon Papers). But Johnson escalated the war further by bombing North Vietnam.
McNamara left the job in 1968. The war eventually claimed the lives of three million Vietnamese and 58,000 Americans.
Almost immediately, he took up the presidency of the World Bank where he remained until 1981, focusing on the developing world.
In later years, he became a prolific author and lecturer. His role in the Vietnam War continued to haunt him, though.
It was his memoir, In Retrospect: The Tragedy and Lessons of Vietnam (1995), which inspired The Fog of War movie.
He described the war as "terribly wrong" owing to a combination of the anti-communist climate of the times, mistaken assumptions of foreign policy and military misjudgements.
Critics claimed his admission came 30 years too late.
In 2004, at the age of 88, he married 70-year-old Diana Byfield. It was his second marriage - his first wife Margaret, to whom he was married for 40 years, died of cancer in 1981.
Robert McNamara once said, "I don't believe we should ever apply our power unilaterally. If we can't persuade nations with similar values, we'd better re-examine our reasoning."