Britain’s involvement in the transatlantic slave trade was an appalling atrocity that has left an “indelible stain” on the world, Prince Charles has acknowledged.

The heir to the UK’s throne made the comments in a speech in Ghana, from where many Africans were shipped away to a life of slavery, most across the Atlantic, on ships from Britain and other nations.

Charles said the “profound injustice” of that legacy could never be forgotten, adding: “At Osu Castle on Saturday, it was especially important to me, as indeed it was on my first visit there 41 years ago, that I should acknowledge the most painful chapter of Ghana’s relations with the nations of Europe, including the United Kingdom.

“The appalling atrocity of the slave trade, and the unimaginable suffering it caused, left an indelible stain on the history of our world.”

Charles had visited Christiansborg Castle in Osu, which originally operated as a Danish slave trade fort and from where it is estimated more than 1.5 million Africans were forced into slavery.

Prince Charles visits Christainborg Castle in Osu. Photograph: Tim Rooke/Rex/Shutterstock

The castle later became the seat of the Ghanaian government after the country’s independence from Britain in 1957.

Britain had been involved in the transatlantic slave trade for more than 200 years by the time it abolished the trade in 1807, although the full abolition of slavery did not follow for another generation.

The British taxpayer paid out large sums in compensation to former slave owners, though none was handed to the people who had been enslaved. Many of them were even forced to work on for years without pay after slavery.

“While Britain can be proud that it later led the way in the abolition of this shameful trade, we have a shared responsibility to ensure that the abject horror of slavery is never forgotten,” Charles told his audience in Ghana.

Charles’ intervention was a significant step towards officially acknowledging the damage the UK helped to cause during the period, with the royal family having faced repeated calls from some quarters to apologise for the country’s part in it.

The prince and his wife, Camilla, are on the second leg of a tour of three African nations, having already visited Gambia, which he congratulated for turning its back on autocratic rule and returning to the Commonwealth, before he heads to Nigeria on Tuesday.

In his speech in Accra, Charles, who was approved as successor to his 92-year-old mother, Queen Elizabeth, as head of the Commonwealth earlier this year, spoke of the role the loose alliance of 53 member states could play in tackling climate change, a key campaigning issue of the prince.

“In such an uncertain and changing world, none of us can know what kind of a planet our grandchildren, and great-grandchildren, will inhabit, but the Commonwealth ... offers us a vital mechanism to help ensure that it is not poisoned and polluted and that its vitality is not compromised,” he said.

They will conclude their tour a week before Charles celebrates his 70th birthday on 14 November.