Television is putting its faith in religion.

Its most surprising success story this year is “The Bible,” the most-watched show on Sunday nights, averaging more than 10 million viewers — on the History Channel, of all places, a cable outlet once best known for Adolf Hitler documentaries. It’s even beating “American Idol” in the ratings.

At a time when TV is struggling, executives have discovered an untapped audience: people who want to connect with God, but would rather do it in their living room than from a church pew.

“It’s clear that there’s a longing for some kind of spirituality, but without being part of a worship community,” said Mary Hess, an associate professor at St. Paul’s Luther Seminary who has written about pop culture and religion. “I think those people are hungry for this kind of stuff.”

One of every five American adults has no religious affiliation, up 33 percent from five years ago, according to a study conducted late last year by the Pew Forum on Religion & Public Life. While some are atheists or agnostics, most say they are turned off by formal religious organizations and prefer to seek spirituality in other ways.

The History Channel isn’t the only network reaching out to this growing audience. “The Great American Bible Challenge” is the most popular series in Game Show Network’s two-decade history. And GMC, a network that specializes in spiritual programming, saw its ratings rise by 80 percent over the course of last year.

“We were faith when faith wasn’t cool,” said CEO Charley Humbard. “It’s nice to be in vogue now.”

The son of pioneering televangelist Rex Humbard, he launched the Gospel Music Channel in 2004 and is preparing to rebrand it as UP to aim for a broader audience.

While the tale of Moses freeing the Israelites may be old hat to earlier generations, it’s a new and exciting adventure story for youngsters who aren’t enrolled in Sunday school.

“The Bible,” a fast-paced, violent series that plays out like an action flick, is co-produced by Roma Downey, who once starred in “Touched by an Angel,” perhaps TV’s most successful series about spirituality. Downey said that one of her friends — a Christian who isn’t a churchgoer — had great fun watching the miniseries with his little boys.

“He would predict that the walls of Jericho were coming down or that Moses would be parting the Red Sea,” said Downey, whose 10-hour miniseries concludes Sunday. “When they happened, his kids just looked at him in amazement. ‘How did you know that?’ ”

While “Touched by an Angel” was a big hit for CBS during its 1994-2003 run, it didn’t inspire a lot of copycats. In fact, the big broadcast networks — unlike cable — have been slow to pick up on religious-themed programming.

“The truth of the matter is that all that stuff is controlled out of New York and Los Angeles and they don’t have the pulse of the country,” said the host of “American Bible Challenge,” Jeff Foxworthy. “As a comedian, I travel to all 50 states, and what’s on the networks is not reflective of what the country is.”

In 1999, CBS aired the miniseries “Jesus,” starring Jeremy Sisto, Gary Oldman and Debra Messing. But since then its director, Roger Young, has had to take his biblical-themed films to cable. His latest, “Barabbas,” airs this weekend on the Reelz­Channel, owned by St. Paul-based Hubbard Broadcasting.

“It’s strange that the broadcast networks walked away,” Young said. “But Hollywood looks down their nose at religious things. It’s a very secular town.”

‘Edgy’ shows got the ax

It’s also a cautious town that has paid the price when it tried to deliver spiritual shows with an edge.

“Nothing Sacred,” which debuted in 1997, featured a liberal Catholic priest who questioned his calling. “The Book of Daniel” (2006) revolved around an Episcopal priest (Aidan Quinn) addicted to painkillers who chatted directly with Jesus. Both set off protests from conservative Christian groups. Both were quickly canceled.

“Most networks want to be careful not to offend anyone,” said Reelz CEO Stan Hubbard, who plucked his channel out of obscurity two years ago by picking up the controversial miniseries “The Kennedys.”

Reelz conducted focus groups before production of “Barabbas” even started. It was surprised to learn that a third of those interviewed were familiar with the tale of the prisoner who was set free to make way for Jesus’ crucifixion, and were interested in watching a story about him. They also were insistent that the story not stray from the biblical version.

“As a business, we actually have more leeway of getting the Kennedy story wrong than we do with Bible stories,” Hubbard said.

TV executives may not want to stir the pot, but they also don’t want to miss an opportunity to make money at a time when it’s hard to generate hits. A total of 13.1 million people tuned in when “The Bible” premiered March 3, making it cable’s No. 1 entertainment telecast of the year.

“Ratings speak in this town,” Downey said. “Now that ‘The Bible’ is cool, you know that producers and agents are calling each other to see if anyone has a faith-based script. It’s going to show networks that there’s an audience for this. If people are crying for a particular brand of ice cream, why not give it to them?”