Hugh Masekela, the trumpeter and singer whose music became associated with the anti-apartheid movement in South Africa, has died at the age of 78.

A statement from his family said he had “passed peacefully” in Johannesburg, where he had long lived and worked. The musician had been suffering from prostate cancer for nearly a decade.

Masekela’s career spanned more than five decades. His song “Soweto Blues”, which marked the 1976 uprising in the South African township, became one of the soundtracks to the struggle against racial segregation.

Another song, “Bring Him Back Home (Nelson Mandela)”, called for the release of the future president during his 28-year-long imprisonment. Written when Masekela was in exile, it was banned by the apartheid regime.

Paying tribute on Facebook, Sal Masekela said his father's life was "the definition of activism and resistance".

"Despite the open arms of many countries, for 30 years he refused to take citizenship anywhere else on this earth. His belief too strong that the pure evil of a systematic racist oppression coculd andd would be crushed. Instead he would continue to fight. He was right," he wrote.

Hugh Masekela's son Sal paid tribute to his father on Facebook(Facebook)

Born in an eastern mining town in 1939, Masekela took to the trumpet with the help of the British anti-apartheid campaigner and Anglican clergyman Trevor Huddleston. He left South Africa at the age of 21 in 1960 to spend what would be three decades in exile.

He became a successful musician in the UK and the US in particular, forming close friendships with jazz legends such as Miles Davis and John Coltrane. In the 1960s he appeared alongside stars such as Janis Joplin, Otis Redding and Jimi Hendrix.

Two decades later he toured with Paul Simon – and in 2012 he went on a European tour with the American singer to celebrate the 25th anniversary of Simon’s “Graceland” album. Masekela also performed at the opening ceremony of the 2010 football World Cup in Johannesburg.

South African President Jacob Zuma said the nation would mourn a man who “kept the torch of freedom alive”.

“It is an immeasurable loss to the music industry and to the country at large. His contribution to the struggle for liberation will never be forgotten,” Zuma said in a statement.

“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 memories of millions across six continents,” Masekela’s family statement said. “Rest in power beloved, you are forever in our hearts.”