Anonymity can have surprisingly big rewards.

Just ask mystery writer Tom Straw, who wrote seven novels under the pseudonym “Richard Castle” and made it to the New York Times best-seller list each time (with the third book, “Heat Rises,” hitting the No. 1 spot).

Straw wrote the books as if he were the fictional mystery writer on the hit ABC series “Castle.” Freed from the limits of novelization — basing a book on a movie or TV series — the writer enjoyed figuring out what Castle’s novels might be like and then setting to work on stories about New York detective Nikki Heat.

While the series was in first run on network television (2009-16), Straw was sworn to secrecy, but the Branford novelist was finally revealed as the author of the Castle books and he is using that fame and success to launch a new novel under his own name — “Buzz Killer” — that he hopes will be the first of a series of New York City-based crime novels.

“It was like keeping the Santa Claus secret, but knowing that there would still be Christmas,” Straw says of the years he spent as an undercover novelist. “The thing you have to know is that I love writing and it was a great collaboration with the creator of the show (Andrew W. Marlowe).”

As the TV series ran, and the quality of the novels became apparent, Straw was tickled and flattered by the rumors that the books were being written by Michael Connelly, Dennis Lehane or one of the other top writers in the field (many of whom made cameo appearances on the show as friends of Castle).

“At the end of the day, I didn’t want to burst the balloon, so I never felt that I wanted my name on the Castle books,” he says.

Straw was tapped by the TV show’s producer for two reasons: He had just published a well-received first mystery novel (“The Trigger Episode”) and he had also worked for many years in television as a writer and producer on series ranging from “Night Court” to “Nurse Jackie.”

The Castle assignment wasn’t all that different from Straw’s position as a TV writer. “Even though you do get a credit on a TV series, you’re still basically ghostwriting. You’re seeing Edie Falco and not seeing who wrote it. When I wrote sketches for Craig Ferguson, it was Craig you saw,” Straw says of his work on “Nurse Jackie” and Ferguson’s late-night talk show.

Straw appreciated the chance to refine his novel writing skills under the cloak of anonymity. Not having his own name on the books freed him up to try new things and to delve deeper into the romantic suspense genre that he wanted to pursue in his own writing. “Castle gave me the fuel to write seven books,” he says.

“Buzz Killer” has a more serious tone than the Castle stories, but it too features a mismatched crime-solving couple — public defender Macie Wild and an ex-cop turned video crime journalist Gunnar Cody — who have almost instant sexual chemistry despite their many personal and philosophical differences.

Macie is defending a client who is charged with committing a murder in the course of his work with a burglary ring. The man is far from “innocent,” but his lawyer believes he is being framed for the murder. Unlike so many TV shows that seem tilted in favor of the police and prosecution, “Buzz Killer” demonstrates the challenges of putting together a good defense when the whole “law and order” system is mobilized against you.

The novel shows us that in New York a defense attorney frequently does not get access to the evidence against his or her client until right before the trial. This puts the accused at a great disadvantage in many cases because the lawyer hasn’t had a chance to thoroughly investigate all of the evidence.

“The inequity in the system adds excitement to the pairing up of Macie and Gunnar,” Straw says of his by-the-book attorney and the ex-cop who is willing to bend the rules in an investigation.

Straw says his TV background taught him the need to grab someone’s attention quickly and to hold them with a story packed with surprises. “A lot of it does come from my TV training,” the novelist says of the high velocity of “Buzz Killer.”

“You can’t clear your throat too long or you’ll lose them. Everyone is looking for a point of entry into a story, who they will be rooting for. I like to give my audience credit for being able to pick up stuff (about the characters) along the way. You can’t dawdle — the responsibility of a writer is not to let the reader’s attention wander. Every chapter has to pull you to the next one,” he says.; Twitter: @joesview