Producing a TV series with original songs in every episode is always an ambitious undertaking. And precious few of them have succeeded.

ABC’s landmark Robert Morse musical “That’s Life” (1968) managed to last one season, NBC’s “Smash” (2012-13) limped along for two, while ABC’s infamous “Cop Rock” (1990) managed just 11 episodes.

With “Galavant,” which debuted Jan. 4 in the “Once Upon a Time” slot, ABC jumps back into the risky musical business with some very high-powered talent. Billed as “a medieval musical fairy tale,” it offers a handsome knight (Joshua Sasse) who teams up with a princess (Karen David) to win back his true love (Mallory Jansen) from the evil king (Timothy Omundson) who has married her.

The songs are by eight-time Oscar winner Alan Menken, best known for his Disney scores “The Little Mermaid,” “Beauty and the Beast” and others; and lyricist Glenn Slater, Menken’s songwriting partner on Disney’s “Tangled” and, on Broadway, “Sister Act” and “Leap of Faith.” Creator-producer Dan Fogelman worked with both of them as the writer of “Tangled.”

“I just loved the premise, a swashbuckling hero gone to seed,” says Menken on a break from recording a 40-piece orchestra for “Galavant” on the Sony scoring stage in December. “I was intrigued by the immediate gratification of television, and also just the form. The level of accessibility that’s required is even greater than in film or theater.”

Menken, who has embraced all kinds of music, from the classic rock of “Little Shop of Horrors” to the Harlem jazz of “Aladdin,” sees “Galavant” as an eclectic stew, “sort of a combination of a Broadway musical-theater form combined with album rock. From a Michael Jackson kind of song to a classical piece, a skiffle song, a cabaret song … anything goes, so long as it’s appropriate and it works.”

What may raise eyebrows for an 8 o’clock show are some of Slater’s sometimes racy, anachronistic lyrics (which, in the pilot, included references to “cajones out to here” for Galavant and King Richard serenading the court with “maybe we could start a genocidal war”).

“How do we get men to watch this?” asks Slater. “How do we get college kids? How do we make this a cultural touchstone rather than just something for a niche audience? That was very much about keeping the humor adult, that it felt edgy and advanced.”

Beyond the songs, there is the comedic chutzpah of Fogelman, who insists, “You need to push envelopes in terms of genre, type and tone. I try and use the Pixar model. Their stuff can have bite and edge and adult themes, risque content or sophisticated subject matter that hopefully goes over the heads of kids.”

It all started nearly two years ago, when Fogelman recruited Menken and Slater to write a song for his sitcom “The Neighbors.” That tune, a Broadway sendup, was nominated for an Emmy, and it led to the three of them collaborating on the pilot for “Galavant.”

They wrote the pilot’s two songs over the course of a month. But when the series was picked up for seven more episodes, they managed to pen 30 more songs in 2½ months — “by far the fastest” they’ve ever worked, Slater says, averaging 2½ days for each song (compared to their average of a week per song when working on a Broadway show).

And while they were working in Menken’s Westchester County, N.Y., studio, the “Galavant” company began shooting “in real castles,” as Fogelman put it, near Bristol, England.

Menken and Slater would work out the placement and idea for each song with Fogelman and the writers. They would write the song, and Menken would create a demo that he would sing that would then be sent over to England.

Menken’s longtime musical director Michael Kosarin met with the actors and adjusted keys if necessary before recording their vocals. Then, in classic movie-musical fashion, the tracks would be played back during shooting and the actors would lip-sync to their own vocals.

“It was like my wildest childhood fantasies coming true,” says Jansen, who plays Galavant’s lost love Madalena (“she’s a psychopath and a nymphomaniac, but we love her,” she says with a laugh). “Alan Menken made some of the most beautiful songs of my childhood, from ‘Pocahontas’ to ‘Little Mermaid.’”

The actors variously cite Monty Python, “Princess Bride” or Mel Brooks as precursors, “taking a genre and twisting it on its ear,” as Omundson puts it. “But it’s so much more subversive than ‘Princess Bride.’ Where we start and where we all end is absolutely unexpected.”

ABC is following its “Nashville” pattern of releasing at least one song on iTunes the Tuesday before each Sunday airing, with a new sing-along video each Thursday. ABC senior VP of music Dawn Soler says a 14-song “Galavant” soundtrack album can be expected after the final episodes air Jan. 25.

Should “Galavant” win an Emmy for its songwriters, Menken will join the ranks of the EGOT crowd. “I don’t think about it,” says Menken. “It’s hard to know where to put that in your value system.”