Legendary South African jazz trumpeter and anti-apartheid activist Hugh Masekela has died at the age of 78 after suffering from cancer.

Masekela, branded the “father of South African jazz”, died in Johannesburg after what his family described as a “protracted and courageous battle with prostate cancer”.

The singer and composer, whose music came to epitomize the country’s anti-apartheid movement, was known locally as “Bra Hugh”.

Born in the South African town of Witbank in 1939, Masekela was predominantly raised by his grandmother who ran an illegal bar for minors. He took up singing and playing piano as a child and then the horn at 14. Before long he became an integral part of the 1950's jazz scene in Johannesburg as a member of the Jazz Epistles.

Masekela, who was married to South African singer and activist Miriam Makeba for two years, was exiled from his country for 30 years.

It was in the UK and the US in the 1960s that he chose to go into exile and there he enjoyed tremendous success and worked with American jazz legend Harry Belafonte.

While there he formed close friendships with jazz legends such as John Coltrane, Miles Davis and Charles Mingus and used his music to raise awareness about the oppressive system of white-minority rule in South Africa.

His son, Selema Mabena Masekela, said on Tuesday that Masekela refused to take citizenship anywhere outside South Africa “despite the open arms of many countries”.

“My father’s life was the definition of activism and resistance. His belief [was] that the pure evil of a systematic racist oppression could and would be crushed. Instead he would continue to fight,” he said.

After spending more than 30 years in exile, Masekela went back to South Africa in the early 1990's after Nelson Mandela was released from prison and the apartheid came to an end.

After returning to his birth country, Masekela continued to speak out about political issues in South Africa. The musician was involved in a number of social initiatives and worked as a director on the board of the Lunchbox Fund - a non-profit organisation that gives a daily meal to students from township schools in Soweto.

Many of Masekela’s compositions centred on the struggle for majority rule and full democratic rights in South Africa. His song “Bring Him Back Home” calling for Mandela to be released from prison morphed into a global anthem for the anti-apartheid movement.

The family statement read: “Hugh’s global and activist contribution to and participation in the areas of music, theatre, and the arts in general is contained in the minds and memory of millions across six continents”.

In October last year, Masekela released a statement that he had been fighting prostate cancer since 2008 and would have to cancel his professional commitments to focus on his health. He said he started treatment after doctors found a “small ‘speck’” on his bladder, and had surgery in March 2016 after the cancer spread.

Masekela also said he felt an “imbalance” and had an eye problem after a fall in April in Morocco in which he sprained his shoulder. He said another tumour was then discovered and he had surgery.

“I’m in a good space, as I battle this stealthy disease, and I urge all men to have regular tests to check your own condition,” his statement said, asking the media for privacy.

Condolences from fans poured out Tuesday on social media paying tribute to the influential musician’s career.

“A baobob tree has fallen,” Nathi Mthethwa, South Africa’s minister for arts and culture, wrote on Twitter. “The nation has lost a one of a kind musician . We can safely say Bra Hugh was one of the great architects of Afro-Jazz and he uplifted the soul of our nation through his timeless music.”

South African President Jacob Zuma expressed his condolences, saying Masekela “kept the torch of freedom alive globally, fighting apartheid through his music and mobilising international support for the struggle for liberation and raising awareness of the evils of apartheid ... His contribution to the struggle for liberation will never be forgotten.”

Masekela inspired generations of musicians in jazz and beyond and collaborated in recent years with South African house music DJ Black Coffee and others. Writing on Twitter on Tuesday, the DJ said: “I have no words".