For a few hours every morning, Dann McDorman sits on his windowed front porch in Brooklyn, a steaming cup of coffee by his side, a computer on his lap and maybe a space heater by his feet if it’s cold. There he sits, for an hour or two, writing novels.

And then he goes to work at Rockefeller Center in Midtown Manhattan, where he is the executive producer of one of MSNBC’s most successful news shows, “The Beat With Ari Melber.”

McDorman’s life has taken an unexpected turn in middle age. Decades after he tucked away dreams of becoming an author, diving into a busy family life and a career in journalism, he tried two years ago to write a novel. It worked: A publisher bought it. And now, his first book, “West Heart Kill,” will be published this week. McDorman has since finished a draft of his second novel and started on a third.

“I never expected this,” he said, awed by his good fortune. “I’m playing with house money.”

While many novelists are published for the first time in midlife or later, McDorman’s experience is unusual because he doesn’t have years’ worth of manuscripts living in a drawer, said his editor, Jennifer Barth, an executive editor at Knopf. Bonnie Garmus, for example, published her outrageously successful novel “Lessons in Chemistry” when she was in her 60s, and while it was her first published work, she had nearly 100 rejections on a previous manuscript, which she was told — again and again — was too long.

McDorman, 47, dreamed of becoming a novelist as a young man. When he was starting out in journalism in his 20s, he tried to carve out a couple hours every day to write, working around the schedule of his terrible graveyard shifts. If he had to get to work at 1 a.m., he’d wake up at 10 p.m. and write for a couple of hours. Or he’d finish work at 4 p.m., take a nap and write. But it never went anywhere, and without ever really making a decision about it, he slowly gave fiction writing up.

Then in the summer of 2021, he jotted down some jacket copy for a mystery novel — a detective stares at a wall of plaques marking the tenure of presidents at an old money hunting club, and wonders why one of the plaques is missing. McDorman showed his wife what he’d written, and she encouraged him to give it a try. So off he went. He finished a first draft in six months.

“I never read a word of it,” his wife, Caroline Smith, said of his writing over the years. “Nothing until this book.”

“West Heart Kill” follows a group of people over a Fourth of July weekend in 1976 at a compound of 7,000 acres shared by a group of wealthy families in upstate New York. There is a detective and there are bodies, but from the beginning, the mystery breaks with convention as McDorman dissects the genre while simultaneously enacting it. (“Not all mysteries begin with the protagonist,” McDorman writes on the first page, “but this one does.”) McDorman said he set out to write a traditional mystery, but “it immediately went off the rails.”

His publisher, Knopf, has taken a significant bet on “West Heart Kill,” a debut novel by an untested author, with a first printing of 150,000 copies. Most books are lucky to sell 10,000 copies.

“There are some people who are offended that he hasn’t played by the rules,” Barth said. “Some readers hate that he’s broken the fourth wall or that he dares to take on these tropes and analyze them in a way that might be different. And that’s what I love about it. It’s anarchic and a little irreverent and he makes it his own.”

While he has not been honing his fiction skills for long, McDorman has been writing and editing for more than 20 years as a journalist, and doing it on deadline. That environment taught him that he couldn’t be precious about his routine, and he certainly couldn’t wait for the fairy of writerly inspiration to land on his shoulder.

“When I was younger, I thought every sentence had to be engraved on a stone tablet by the finger of God,” he said. “But no, you just go. Go, go, go, go, go.”

Barth said that his job and his experience in journalism also gives him a different view of the publishing side of the process.

“It does put things in perspective,” she said. “When you’re working on the type of news he is and you don’t get something you were hoping for — well, you know it’s not a war.”

At “The Beat With Ari Melber,” McDorman runs a team of about 15 journalists and, along with Melber, decides what stories to cover and how to approach them. He manages the live control room and lives at the mercy of the news, which has no regard for sleep schedules or weekends. He also makes grim decisions about where to freeze videos of a shooting or whether to include brutal images of war.

In his fiction, McDorman said, he dives into esoteric worlds and creates little fantasies where no real person gets hurt.

“The waking life and the dream life have nothing to do with each other,” McDorman said.

His colleagues have been very supportive, he said, but some have also been a bit mystified. Indeed, when he first starting telling co-workers he’d sold a novel, he felt “a little goofy” and shy about it.

“You don’t necessarily want your dentist to be a song and dance man,” he said. “Now, lots of people know, but I kept it under wraps for a while.”

None of this success was a given. McDorman’s father didn’t finish high school, enlisting in the Army instead. He was 20 when McDorman was born and his mother was 26. His father struggled with alcoholism, and McDorman was the first person on his father’s side of the family to attend college.

“For someone working in cable news for so long, he’s not nearly as cynical or hard bitten as you’d expect,” said Susie Banikarim, a longtime friend who co-hosts a podcast called “In Retrospect.” “He maintains a worldview that’s optimistic, partially because he has beaten so many odds himself. Even if he didn’t have this wildly successful turn of events, what he’s accomplished with his life given where he came from is really remarkable.”

When McDorman started telling friends about his book deal, which Banikarim described as “winning the middle-age lottery,” he noticed a curious reaction: Many of his friends started to cry — they would cry, then he would cry and they’d cry together. It happened a few times, he said, frequently enough that he started to wonder why.

“I think it’s because at this stage in our lives, this kind of thing doesn’t happen,” he said. “Your life is kind of set, you know. Everyone has jobs, they’ve got kids, they’re trying to figure out college or high school,” he continued. “There are a lot of closed doors, or at least it feels that way. So when something like this happens, it’s a reminder that maybe there are more doors open than you might think.”