Harry Potter creator JK Rowling has accepted a substantial charity donation from the law firm that revealed she was writing under a pseudonym.

The writer brought a legal action against Chris Gossage, a partner at Russells Solicitors, and his friend, Judith Callegari.

Rowling was revealed as the writer of crime novel The Cuckoo’s Calling in a Sunday Times article.

The author had published the book under the pen name Robert Galbraith.

Rowling’s solicitor told Mr Justice Tugendhat that Russells had contacted the writer’s agent after the story was published, revealing it was Mr Gossage who had divulged the confidential information to Ms Callegari, BBC reports.

Ms Callegari then revealed the information in the course of a Twitter exchange with a journalist.

The court heard Rowling had been “left dismayed and distressed by such a fundamental betrayal of trust”.

Mr Gossage, Ms Callegari and Russells all apologised and the firm agreed to pay the author’s legal costs.

It also agreed to make a payment, by way of damages, to The Soldiers’ Charity, formerly known as the Army Benevolent Fund.

Rowling explained that she was donating the money “partly as a thank you to the army people” who helped her with research.

“But also because writing a hero who is a veteran has given me an even greater appreciation and understanding of exactly how much this charity does for ex-servicemen and their families, and how much that support is needed,” she said.