The BBC has apologised for failing to warn the Duke of Sussex before broadcasting and publishing online an image from a neo-Nazi social media group that called him a “race traitor” and depicted the royal with a gun pointed at his head.

The image, published on BBC Online and broadcast on News at 10, was a stylised collage from an online post on a far-right platform, which also included blood splatter and a swastika, and was captioned: “See ya later race traitor. #racetraitor.”

It raised “serious security concerns” for Prince Harry and “caused his family great distress specifically while his wife was nearly five months pregnant”, a spokesperson for the duke told the Guardian.

Both the BBC internally and the broadcasting watchdog Ofcom rejected a complaint by the duke, ruling that the use of the image in a report about the activities of the group was clearly in the public interest. However, the BBC has now apologised for not warning the Duke and Duchess of Sussex before broadcast and online publication in December last year.

The corporation said it recognised that “before publishing seriously offensive material we need to be vigilant in balancing the impact on individuals against the wider good which may be served by publication”.

In a letter to Harry, the BBC also said it had committed to strengthen its guidance on the use of content that poses risk of offence to the individual portrayed.

Harry’s spokesperson said: “His Royal Highness welcomes the letter from the BBC relating to the shocking image published by BBC News last year as part of a report on the activities of a British neo-Nazi group with links in the US.

“His Royal Highness raised the issue with Ofcom about the rebroadcasting of this racist image due to his concerns that hateful and dangerous propaganda had been spread globally by the world’s most important public service broadcaster. Due to the credibility of the BBC, their choice to publicise this material created an open door for all other media to reproduce it.”

While welcoming the BBC’s apology, Harry did not agree with the decision to broadcast the image. “His Royal Highness maintains that instead of reproducing the image and giving a platform to something that would have only been seen by a few, it should have been described so that others would not potentially be influenced by such an inflammatory image,” the spokesperson said.

The BBC Online article, which investigated the activities of Sonnenkrieg Division, reported: “One image suggests that Prince Harry should be shot for marrying someone of mixed race and exclaims ‘see ya later race traitor’.” The BBC reduced the size of the image online the following day, and removed it two days later. The corporation said the image had been removed because public interest in the article had reduced.

Harry was the only person to complain to Ofcom about the issue.

After the BBC report, Michal Szewczuk, 19, from Leeds, who created the image, was sentenced to four years and three months in a young offender institution, after pleading guilty to two counts of encouraging terrorism and five counts of possession of terrorist material, including the White Resister Manual and an al-Qaida training manual.

Oskar Dunn-Koczorowski, 18, from Chiswick, west London, who admitted two counts of encouraging terrorism, was sentenced to an 18-month detention and training order.

The duke had complained to the BBC that publication of the image fell “below the generally accepted standards as to harmful and offensive material” and there was insufficient justification to warrant the publishing of the image, given that it had been created by the group to incite criminal action.

The BBC did not uphold the complaint, maintaining publication was in the public interest. Ofcom also did not uphold the complaint, ruling there was “clear public interest” in conveying “clearly and impactfully the offensive nature of the group’s messages” and that it was editorially justified.

Harry later discussed his concerns with the BBC’s director general, Tony Hall.

Prince Harry has spoken out on racism on several occasions. In an unprecedented statement when news of his relationship with Meghan Markle became public, he criticised “racial overtones” in reporting. Earlier this year he said “unconscious bias” passed from generation to generation could lead to racist behaviour in people who do not believe they are racist.

An Ofcom spokesperson said: “This image was highly offensive, but in our opinion, its inclusion in the article was editorially justified as it was used to condemn and illustrate the racist group’s activities, which was in the public interest.”

A BBC source said: “This was an important piece of journalism which led to the arrest, conviction and imprisonment of two members of a neo-Nazi group. The image of the Duke of Sussex was included to show the abhorrent nature of their behaviour and Ofcom has subsequently concluded that there was a clear editorial rationale for using the image which, in the context of the news report, was considered unlikely to incite crime.

“Naturally we regret the distress caused and we apologised for failing to warn Kensington Palace in advance that it was to be published.”