Image caption Masekela was given his first trumpet at the age of 14

Legendary jazz trumpeter Hugh Masekela, a leading figure in the struggle to end apartheid and "the father of South African jazz", has died aged 78.

In a statement, his family said he had "passed peacefully" in Johannesburg "after a protracted and courageous battle with prostate cancer".

Masekela gained global recognition with his distinctive Afro-Jazz sound and hits such as Soweto Blues.

The 1977 song became synonymous with the anti-apartheid movement.

In a statement, South African President Jacob Zuma said Masekela's death was "an immeasurable loss to the music industry and to the country at large".

Zuma continued: "His contribution to the struggle for liberation will never be forgotten."

Media playback is unsupported on your device Media caption Hugh Masekela on music and his relationship with South Africa

Born in the South African town of Witbank in 1939, Masekela was inspired to learn the trumpet after seeing Kirk Douglas play Bix Beiderbecke in the 1950 film Young Man with a Horn.

He persuaded one of his teachers - the anti-apartheid crusader Father Trevor Huddleston - to buy him an instrument, promising to stay out of trouble in return.

Image copyright Getty Images Image caption He helped open the 2010 World Cup in South Africa with fellow musician Femi Kuti

In 1960, aged 21, he left South Africa to begin what would be 30 years in exile from the land of his birth.

Under the tutelage of Dizzy Gillespie and Louis Armstrong, he was encouraged to develop his own unique style.

In 1967, he performed at the Monterey Pop Festival alongside Janis Joplin, Otis Redding, Ravi Shankar, The Who and Jimi Hendrix.

The following year, his instrumental single Grazing in the Grass topped the charts in the US and became a worldwide hit.

Masekela returned to South Africa in 1990 following the release of Nelson Mandela, whose freedom he had called for in his 1986 anthem Bring Home Nelson Mandela.

In June 2010, he performed at both the opening concert of the Fifa World Cup and the tournament's opening ceremony in Soweto's Soccer City.

Image copyright Getty Images Image caption Masekela's many friends included Paul Simon, seen here performing with him in 2014

In their statement, Masekela's family described him as "a loving father, brother, grandfather and friend" who would be "forever in our hearts".

"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," it continued.

"We are blessed and grateful to be part of a life and ever-expanding legacy of love, sharing and vanguard creativity that spans the time and space of six decades."

Details of memorial and burial services, the family said, would be released "in due course".

South African musician Loyiso Bala was among many to mark his death on Twitter.

Analysis by Pumza Fihlani, BBC News, Johannesburg

The passing of Hugh Masekela is the end of an era and has saddened many across the country. Described as a legend, he was celebrated for his contribution to music, theatre and social and political activism.

The jazz musician whose Soweto Blues served as one of the soundtracks to the anti-apartheid movement was never one to shy away from challenging the status quo.

In a career spanning six decades, he gained international recognition with his distinctive sound, a constant reminder of his love for South Africa - a country whose political turmoil once forced him into exile.

Diagnosed with prostate cancer in 2008, the world-acclaimed musician - affectionately known as Bra Hugh - spent the last months of his life encouraging men to go for regular cancer check-ups.

Follow us on Facebook, on Twitter @BBCNewsEnts, or on Instagram at bbcnewsents. If you have a story suggestion email entertainment.news@bbc.co.uk.