Gary S. Paxton’s 1976 solo debut. (NewPax Records)

Gary S. Paxton, a musical maverick who wrote more than 2,000 songs and produced the pop hits “Alley-Oop” and “Monster Mash,” and who later overcame addiction and transitioned to a career as a gospel musician, died July 17 at an assisted-living center in Branson, Mo. He was 77.

The cause was complications of heart surgery and liver disease, said his wife, Vicki Sue Paxton.

Mr. Paxton had his first taste of success as one-half of Skip & Flip, a late 1950s pop duo that broke into the Top 20 with “It Was I,” a bittersweet song about a jilted lover, and “Cherry Pie,” a cover of Marvin & Johnny’s doo-wop hit. Less a performer than a songwriter, Mr. Paxton quickly tired of touring and quit the road in favor of the Hollywood recording life.

He and fellow producer Kim Fowley churned out “Alley-Oop” (1960) with a group of studio musicians and friends he called the Hollywood Argyles. The record, which became a No. 1 hit, was written by country songwriter Dallas Frazier and was based on a comic-strip character of the same name who rode a pet dinosaur and traveled through time.

Two years later, Mr. Paxton had his second No. 1 with “Monster Mash,” released on his Garpax label. The devilishly addictive pop song about a mad scientist whose lab work incites a dance craze was written by singer Bobby “Boris” Pickett, who had wowed audiences with an onstage impersonation of horror-film actor Boris Karloff and now sang about “a graveyard smash” that “caught on in a flash.”

Gary S. Paxton at a Hollywood recording studio in 1966. (Ace Records/Alec Palao)

Mr. Paxton worked with dozens of artists in Los Angeles — including the rock-and-roll group Paul Revere & the Raiders, the pop band the Association, and jazz vocalists the Four Freshmen — before moving to Bakersfield, Calif., in 1967 and turning his attention to country music.

The change of scenery was short lived. Mr. Paxton said he used his newfound wealth to acquire a marina, hotel, mountain cabins and music store, as well as a series of recording studios, but “lost it all” because of drugs and alcohol and moved to Nashville in 1970.

One year after he arrived, his business partner Thomas Wayne was killed in a car wreck that Mr. Paxton believed was a suicide. “It stopped me in my tracks,” Mr. Paxton wrote in an online biography. “I walked into a church — stoned on drugs — and got saved!”

He stopped doing drugs and drinking alcohol and began working with gospel artists, including the Blackwood Brothers quartet and singer-songwriter Don Francisco, and in 1976 released his first solo album: “The Astonishing, Outrageous, Amazing, Incredible, Unbelievable, Different World of Gary S. Paxton.”

The gospel record railed against nuclear proliferation and drug abuse in playful tracks such as “You Ain’t Smokin’ Them Cigarettes (Baby, They’re Smokin’ You),” and earned Mr. Paxton a Grammy award for best inspirational performance.

Its cover featured a heavily bearded Mr. Paxton emerging from a Nashville sewer with a black cowboy hat and sunglasses in hand. At the bottom of the image, a parenthetical line offered encouragement to skeptical listeners: “You’d be surprised . . . it makes a lot of sense!”

Gary Sanford Paxton was born Larry Wayne Stevens on May 18, 1939, to an unmarried teenage couple in Coffeyville, Kan. Raised by foster parents, he learned the story of his birth only at 17, when his mother introduced herself while he was dining at a restaurant.

In his biography, Mr. Paxton said he was molested by a neighbor at 7, started writing songs at 10, and one year later contracted spinal meningitis, which left him crippled for three years and caused him to turn even more toward music.

He began performing with an electric Stratocaster guitar after moving to Tucson with his family as a teenager. A poor student, he dropped out of high school and wed 14-year-old Betty Jean Brown, the first of his several marriages, at age 17.

Mr. Paxton was nearly killed in 1980, when he was shot twice and severely beaten by a pair of men who, Mr. Paxton said, were sent by a country singer who wanted out of his contract. “In the name of Jesus,” Mr. Paxton shouted repeatedly at the time, “you cannot kill me!” They did not, though he was sidelined from music for several years.

Mr. Paxton became a public figure again in the late 1980s when The Washington Post reported that the gospel singer Tammy Faye Bakker was infatuated with Mr. Paxton. He denied that a romantic relationship existed. Rumors of a possible affair were linked to Bakker’s subsequent divorce from her husband, televangelist Jim Bakker.

In addition to his wife of 14 years, the former Vicki Sue Roberts, survivors include three sons; two daughters; a brother; and nine grandchildren.

Mr. Paxton was inducted into the Country Gospel Music Hall of Fame in 1998, and in later years performed under the moniker Grandpa Rock, wearing a mask, gold boots and a red leather coat.