Nelson Mandela, the towering figure of Africa's struggle for freedom and a hero to millions around the world, has died at the age of 95.
South Africa's first black president died in the company of his family at home in Johannesburg after years of declining health that had caused him to withdraw from public life.
The news was announced to the country by the current president, Jacob Zuma, who in a sombre televised address said Mandela had "departed" around 8.50pm local time and was at peace.
"This is the moment of our deepest sorrow," Zuma said. "Our nation has lost its greatest son … What made Nelson Mandela great was precisely what made him human. We saw in him what we seek in ourselves.
"Fellow South Africans, Nelson Mandela brought us together and it is together that we will bid him farewell."
Zuma announced that Mandela would receive a state funeral and ordered that flags fly at half-mast.
Mandela's two youngest daughters were at the premiere of the biopic Mandela: Long Walk to Freedom in London last night. They received the news of their father's death during the screening in Leicester Square and immediately left the cinema.
Barack Obama led tributes from world leaders, referring to Mandela by his clan name – Madiba. The US president said: "Through his fierce dignity and unbending will to sacrifice his own freedom for the freedom of others, Madiba transformed South Africa – and moved all of us.
"His journey from a prisoner to a president embodied the promise that human beings – and countries – can change for the better. His commitment to transfer power and reconcile with those who jailed him set an example that all humanity should aspire to, whether in the lives of nations or our own personal lives."
David Cameron said: "A great light has gone out in the world" and described Mandela as "a hero of our time".
FW de Klerk – the South African president who freed Mandela, shared the Nobel peace prize with him and paved the way for him to become South Africa's first post-apartheid head of state – said the news was deeply saddening for South Africa and the world.
"He lived reconciliation. He was a great unifier," De Klerk said.
Throughout Thursday night and into Friday morning people gathered in the streets of South Africa to celebrate Mandela's life.
In Soweto people gathered to sing and dance near the house where he once lived. They formed a circle in the middle of Vilakazi Street and sang songs from the anti-apartheid struggle. Some people were draped in South African flags and the green, yellow and black colours of Mandela's party, the African National Congress.
"We have not seen Mandela in the place where he is, in the place where he is kept," they sang, a lyric anti-apartheid protesters had sung during Mandela's long incarceration.
Several hundred people took part in lively commemorations outside Mandela's final home in the Houghton neighbourhood of Johannesburg. A man blew on a vuvuzela horn and people made impromptu shrines with national flags, candles, flowers and photographs.
Mandela was taken to hospital in June with a recurring lung infection and slipped into a critical condition, but returned home in September where his bedroom was converted into an intensive care unit.
His death sends South Africa deep into mourning and self-reflection, nearly 20 years after he led the country from racial apartheid to inclusive democracy.
But his passing will also be keenly felt by people around the world who revered Mandela as one of history's last great statesmen, and a moral paragon comparable with Mohandas Karamchand Gandhi and Martin Luther King.
It was a transcendent act of forgiveness after spending 27 years in prison, 18 of them on Robben Island, that will assure his place in history. With South Africa facing possible civil war, Mandela sought reconciliation with the white minority to build a new democracy.
He led the African National Congress to victory in the country's first multiracial election in 1994. Unlike other African liberation leaders who cling to power, such as Zimbabwe's Robert Mugabe, he then voluntarily stepped down after one term.
Mandela was awarded the Nobel peace prize in 1993.
At his inauguration a year later, the new president said: "Never, never, and never again shall it be that this beautiful land will again experience the oppression of one by another … the sun shall never set on so glorious a human achievement. Let freedom reign. God bless Africa!"
Born Rolihlahla Dalibhunga in a small village in the Eastern Cape on 18 July 1918, Mandela was given his English name, Nelson, by a teacher at his school.
He joined the ANC in 1943 and became a co-founder of its youth league. In 1952, he started South Africa's first black law firm with his partner, Oliver Tambo.
Mandela was a charming, charismatic figure with a passion for boxing and an eye for women. He once said: "I can't help it if the ladies take note of me. I am not going to protest."
He married his first wife, Evelyn Mase, in 1944. They were divorced in 1957 after having three children. In 1958, he married Winnie Madikizela, who later campaigned to free her husband from jail and became a key figure in the struggle.
When the ANC was banned in 1960, Mandela went underground. After the Sharpeville massacre, in which 69 black protesters were shot dead by police, he took the difficult decision to launch an armed struggle. He was arrested and eventually charged with sabotage and attempting to overthrow the government.
Conducting his own defence in the Rivonia trial in 1964, he said: "I have cherished the ideal of a democratic and free society in which all persons live together in harmony and with equal opportunities.
"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."
He escaped the death penalty but was sentenced to life in prison, a huge blow to the ANC that had to regroup to continue the struggle. But unrest grew in townships and international pressure on the apartheid regime slowly tightened.
Finally, in 1990, FW de Klerk lifted the ban on the ANC and Mandela was released from prison amid scenes of jubilation witnessed around the world.
In 1992, Mandela divorced Winnie after she was convicted on charges of kidnapping and accessory to assault.
His presidency rode a wave of tremendous global goodwill but was not without its difficulties. After leaving frontline politics in 1999, he admitted he should have moved sooner against the spread of HIV/Aids in South Africa.
His son died from an Aids-related illness. On his 80th birthday, Mandela married Graça Machel, the widow of the former president of Mozambique. It was his third marriage. In total, he had six children, of whom three daughters survive: Pumla Makaziwe (Maki), Zenani and Zindziswa (Zindzi). He has 17 grandchildren and 14 great-grandchildren.
Archbishop Desmond Tutu, who headed the truth and reconciliation committee after the fall of apartheid, said: "He transcended race and class in his personal actions, through his warmth and through his willingness to listen and to emphasise with others. And he restored others' faith in Africa and Africans."
Mandela was diagnosed with prostate cancer in 2001 and retired from public life to be with his family and enjoy some "quiet reflection". But he remained a beloved and venerated figure, with countless buildings, streets and squares named after him. His every move was scrutinised and his health was a constant source of media speculation.
Mandela continued to make occasional appearances at ANC events and attended the inauguration of the current president, Jacob Zuma. His 91st birthday was marked by the first annual "Mandela Day" in his honour.
He was last seen in public at the final of the 2010 World Cup in Johannesburg, a tournament he had helped bring to South Africa for the first time. Early in 2011, he was taken to hospital in a health scare but he recovered and was visited by Michelle Obama and her daughters a few months later.
In January 2012, he was notably missing from the ANC's centenary celebrations due to his frail condition. With other giants of the movement such as Tambo and Walter Sisulu having gone before Mandela, the defining chapter of Africa's oldest liberation movement is now closed.