LONDON — An ex-military man tries his hand at writing, publishes a debut detective novel, and wins critical acclaim. But here’s the twist in the tale: The true identity of the author is none other than ‘‘Harry Potter’’ creator J.K. Rowling.

It’s impressive literary wizardry by Rowling, who said she relished the freedom of writing ‘‘The Cuckoo’s Calling’’ under her pseudonym Robert Galbraith.

‘‘I hoped to keep this secret a little longer because being Robert Galbraith has been such a liberating experience,’’ she said in a statement released by her publicist on Sunday. ‘‘It has been wonderful to publish without hype or expectation, and pure pleasure to get feedback from publishers and readers under a different name.’’

‘‘The Cuckoo’s Calling,’’ a story about a war veteran turned private investigator who is called in to probe the mysterious death of a model, was published to rave reviews in April by Sphere, part of publisher Little, Brown & Co.

Get The Weekender in your inbox:

The Globe's top picks for what to see and do each weekend, in Boston and beyond.

The Sunday Times claimed it was investigating ‘‘how a first-time author with a background in the army and the civilian security industry could write such an assured debut novel’’ when it connected the dots. The paper said clues included the fact that Rowling and Galbraith shared the same agent and editor, and that Little, Brown published Rowling’s novel for adults, ‘‘The Casual Vacancy.’’ It also said the book’s style and subject matter resembled Rowling’s work.

Rowling’s publicist confirmed the paper’s detective work was correct, and the news helped the novel climb straight to the top of Amazon’s best-selling list Sunday.

In her statement, Rowling thanked her editor David Shelley, the publishing staff who worked on the book without knowing her identity, and the reviewers who praised it without knowing about her authorship.

She added that ‘‘Galbraith’’ planned to keep writing the series, and her publisher said that the second book is expected to be published next summer. Now that her identity is revealed, Little, Brown said ‘‘The Cuckoo’s Calling’’ will be reprinted with a revised author biography.

On its website, the publisher marketed the book as a classic crime novel in the tradition of P.D. James and Ruth Rendell. It said the novel, whose central character is named Cormoran Strike, was the first of a series of crime novels to come.

The publisher described Galbraith as an ex-military man, married with two sons, who wrote the novel based on experiences from his military life. Revealingly, it also stated that Galbraith was a pseudonym.

The publisher lists many favorable reviews to the book, including critics who called it ‘‘a scintillating debut novel’’ and who praised Galbraith for his ‘‘superb flair as a mystery writer.’’

Rowling recently turned to writing for grown-ups after becoming the world’s most successful living writer with the ‘‘Harry Potter’’ books, which sold more than 450 million copies worldwide.

Reviews for her highly-anticipated novel ‘‘The Casual Vacancy,’’ published last year, were mixed. Some praised the book, a bleak tale about class warfare and the darker sides to a community in small-town England, for tackling difficult subjects, but others thought it lacked the magic touch that made Rowling’s books of wizardry so popular.