A British law firm has apologized to J.K. Rowling and will make a "substantial" donation to a military veterans charity after spilling the beans about the bestselling author's recent thriller written under a pseudonym.

Law firm Russells, which has worked for Rowling, recently revealed that one of its partners accidentally leaked the secret that the Harry Potter creator was actually behind the modestly selling new mystery novel The Cuckoo's Calling, attributed to a debut writer named Robert Galbraith.

The individual had shared the information with a friend, who subsequently tipped off a columnist for the Sunday Times newspaper. The paper revealed Rowling's secret earlier this month.

Rowling, who filed a suit against the lawyer and the friend, was left "angry and distressed that her confidences had been betrayed," Rowling's attorney, Jenny Afia, told Britain's High Court on Wednesday.

"As a reflection of their regret for breach of the claimant's confidence, including frustrating the claimant's ability to continue to write anonymously under the name Robert Galbraith, the defendants are here today to apologize publicly to the claimant," Afia said.

Russells has agreed to pay Rowling's legal costs and make a donation to The Soldiers' Charity, a group that offers support to former military personnel and their families.

Writing under the pseudonym Robert Galbraith (purportedly a retired investigator penning his debut novel), Rowling released The Cuckoo's Calling in the U.K. and U.S. in April.

Sales skyrocket after revelation

Though favourably reviewed by a handful of critics, it sold just 1,500 copies in the past few months. However, sales have skyrocketed since the Sunday Times exposed the true author.

The Cuckoo's Calling revolves around Cormoran Strike, a troubled former war vet who lost a leg in Afghanistan. Now a private detective, he is tasked with investigating the death of a supermodel in London. Rowling has said she drew on conversations with war vets and active soldiers to create the character.

"This donation is being made to The Soldiers' Charity partly as a thank you to the army people who helped me 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," Rowling said in a statement.

She is also donating all royalties from the book to charity for the next three years. A second Cormorant Strike novel is set for publication in 2014.

The Cuckoo's Calling was published by Little, Brown, which also released Rowling's first novel for adults — The Casual Vacancy — to incredible hype and ultimately mixed reviews in 2012.

A former single mother and welfare recipient, Rowling is now one of the world's best-read writers and among the U.K.'s wealthiest people. She made her success with Harry Potter and has sold more than 400 million copies of the teen wizard novels around the globe.

With files from The Associated Press