Jailed for 27 years, he emerged to become the country's first black president and to play a leading role in the drive for peace in other spheres of conflict. He won the Nobel Peace Prize in 1993. His charisma, self-depreciating sense of humour and lack of bitterness over his harsh treatment, as well as his amazing life story, partly explain his extraordinary global appeal. Since stepping down as president in 1999, Mr Mandela has become South Africa's highest-profile ambassador, campaigning against HIV/Aids and securing his country's right to host the 2010 football World Cup.
Mr Mandela - diagnosed with prostate cancer in 2001 - was also involved in peace negotiations in the Democratic Republic of Congo, Burundi and other countries in Africa and elsewhere. In 2004, at the age of 85, Mr Mandela retired from public life to spend more time with his family and friends and engage in "quiet reflection".
"Don't call me, I'll call you," he warned anyone thinking of inviting him to future engagements.
The former president had made few public appearances since largely retiring from public life. In November 2010, his office released photos of a meeting he had held with members of the US and South African football teams. In late January 2011 he was admitted to a Johannesburg hospital for what were described as "specialised tests" with the South African presidency reminding a concerned nation that Mr Mandela has had "previous respiratory infections".
Raised by royalty
He was born in 1918 into the Xhosa-speaking Thembu people in a small village in the eastern Cape of South Africa. In South Africa, he is often called by his clan name - "Madiba". Born Rolihlahla Dalibhunga, he was given his English name, Nelson, by a teacher at his school.
His father, a counsellor to the Thembu royal family, died when Nelson Mandela was nine, and he was placed in the care of the acting regent of the Thembu people, chief Jongintaba Dalindyebo. He joined the African National Congress in 1943, first as an activist, then as the founder and president of the ANC Youth League. Eventually, after years in prison, he also served as its president. He married his first wife, Evelyn Mase, in 1944. They were divorced in 1957 after having three children. Mr Mandela qualified as a lawyer and in 1952 opened a law practice in Johannesburg with his partner, Oliver Tambo.
Together, Mr Mandela and Mr Tambo campaigned against apartheid, the system devised by the all-white National Party which oppressed the black majority. In 1956, Mr Mandela was charged with high treason, along with 155 other activists, but the charges against him were dropped after a four-year trial. Resistance to apartheid grew, mainly against the new Pass Laws, which dictated where black people were allowed to live and work.
In 1958, Mr Mandela married Winnie Madikizela, who was later to take an active role in the campaign to free her husband from prison. The ANC was outlawed in 1960 and Mr Mandela went underground. Tension with the apartheid regime grew, and soared to new heights in 1960 when 69 black people were shot dead by police in the Sharpeville massacre.
This marked the end of peaceful resistance and Mr Mandela, already national vice-president of the ANC, launched a campaign of economic sabotage. He was eventually arrested and charged with sabotage and attempting to violently overthrow the government.
Conducting his own defence in the Rivonia court room, Mr Mandela used the stand to convey his beliefs about democracy, freedom and equality in his most famous speech: "I have cherished the ideal of a democratic and free society in which all persons live together in harmony and with equal opportunities," he said. "It is an ideal which I hope to live for and to achieve. But if needs be, it is an ideal for which I am prepared to die."
In the winter of 1964 he was sentenced to life in prison.
In the space of 12 months between 1968 and 1969, Mr Mandela's mother died and his eldest son was killed in a car crash but he was not allowed to attend the funerals. He remained in prison on Robben Island for 18 years before being transferred to Pollsmoor Prison on the mainland in 1982.
As Mr Mandela and other ANC leaders languished in prison or lived in exile, the youths of South Africa's black townships did their best to fight white minority rule. Hundreds were killed and thousands were injured before the schoolchildren's uprising was crushed. In 1980, Mr Tambo, who was in exile, launched an international campaign to release Mr Mandela. The world community tightened the sanctions first imposed on South Africa in 1967 against the apartheid regime.
The pressure produced results, and in 1990, President FW de Klerk lifted the ban on the ANC, and Mr Mandela was released from prison and talks on forming a new multi-racial democracy for South Africa began.
Nobel Peace Prize
In 1992, Mr Mandela divorced his wife, Winnie, after she was convicted on charges of kidnapping and accessory to assault. In December 1993, Mr Mandela and Mr de Klerk were awarded the Nobel Peace Prize. Five months later, for the first time in South Africa's history, all races voted in democratic elections and Mr Mandela was overwhelmingly elected president. Mr Mandela's greatest problem as president was the housing shortage for the poor, and slum townships continued to blight major cities.
He entrusted his deputy, Thabo Mbeki, with the day-to-day business of the government, while he concentrated on the ceremonial duties of a leader, building a new international image of South Africa. In that context, he succeeded in persuading the country's multinational corporations to remain and invest in South Africa.
On his 80th birthday, Nelson Mandela married Graca Machel, the widow of the former president of Mozambique. He continued travelling the world, meeting leaders, attending conferences and collecting awards after stepping down as president.
After his official retirement, his public appearances were mostly connected with the work of the Mandela Foundation, a charitable fund that he founded. On his 89th birthday, he formed The Elders, a group of leading world figures to offer their expertise and guidance "to tackle some of the world's toughest problems".
Possibly his most noteworthy intervention of recent years came early in 2005, following the death of his only son, Makgatho. In a country where taboos still surround the Aids epidemic, Mr Mandela announced that his son had died of Aids, and urged South Africans to talk about Aids " to make it appear like a normal illness". He also played a key role in the decision to let South Africa host the 2010 football World Cup and appeared at the closing ceremony.