Sam Simon, the writer credited with giving life to “The Simpsons,” the prime-time animation hit that became the longest-running scripted show in television history, has died. He was 59.

His death was announced Monday by the Sam Simon Foundation. He died Sunday at his home in Los Angeles, according to Variety, citing Al Jean, an executive producer for the show. Simon was diagnosed in November 2012 with colorectal cancer and was told months later that it was terminal. Outliving his prognosis, he spent his final years giving away his fortune, which he estimated in the hundreds of millions of dollars, to causes focused on animal welfare.

A writer on TV series including “Taxi” and “Cheers,” Simon oversaw the writing of “The Simpsons” for its formative first four years. Tensions with the show’s creator, Matt Groening, contributed to his departure, and the show continued for more than two more decades without him.

Hailed as “the show’s true architect,” Simon “assembled the original ‘Simpsons’ writing room, which has become the stuff of legend,” John Ortved wrote in his 2009 book, “The Simpsons: An Uncensored, Unauthorized History.”

It was “the cigar-smoking, hard-gambling, brilliant” Simon, Ortved wrote, who took the animated shorts that Groening had created for “The Tracey Ullman Show” and “transformed them into the hysterical half-hour episodes that America fell in love with.”

The result was the made-up city of Springfield, home to the Simpson family – Homer and Marge, and their children, Bart, Lisa and Maggie.

“The revolution of ‘The Simpsons’ would be that these characters had real emotion,” Simon recalled in a 2013 interview with the Archive of American Television, “unlike Bugs Bunny, who was very funny, but he didn’t have an emotional inner life that you could go, ‘Oh my god, I went through that.’ ”

Though he created characters including C. Montgomery Burns, the money-hoarding executive, Simon said he felt a connection with Homer, because the “raging child that is within him is something that a lot of people, including myself, can relate to.”

Simon told CBS’s “60 Minutes” in 2007 that his work “turns me into a monster.” Colleagues didn’t disagree. The New York Times magazine, in 2001, quoted Groening as calling Simon “brilliantly funny and one of the smartest writers I’ve ever worked with, although unpleasant and mentally unbalanced.”

Regarding his departure after the 1992 season, Simon said he had grown unhappy as his responsibilities expanded beyond writing. He retained the title of executive producer — along with Groening and James Brooks — and said he collected tens of millions of dollars annually as the show continued.

Simon said his favorite episode had Marge, insulted one time too many by Homer, consider and ultimately decline romantic overtures by a French bowling instructor, voiced by Albert Brooks. The season-one episode, written by John Swartzwelder, won a 1990 Emmy Award.

“It was the first time I saw that this show could be something beyond what a normal sitcom could do,” Simon said. “This was a story about a frustrated housewife who meets someone romantic and wants to have an affair, and you’re on her side. And I just thought, ‘This is groundbreaking.’ ”

Ortved’s book quoted Wallace Wolodarsky, a “Simpsons” writer from 1989 to 1992, as saying, “Sam opened our eyes to the possibilities of what an animated show could be, which is to say we could go anywhere in the world, we could do anything, and that was incredibly liberating.”

Samuel Michael Simon was born in Los Angeles on June 6, 1955, and raised in Beverly Hills. He was one of two children of Arthur Simon, a women’s clothing manufacturer, and the former Joan Feld, who owned an art gallery.

His only-in-Hollywood formative experiences included seeing his runaway dog returned by Elvis Presley, in a limousine, and walking in on his mother and Groucho Marx “in a compromising position in my parents’ bedroom.”

An artist from an early age, he drew illustrations to accompany stories on a locally televised children’s program. At Beverly Hills High School, he wrestled and played football and was named “most talented” for the cartoons he contributed to the school newspaper, according to a 2014 Vanity Fair profile.

At Stanford University, he studied psychology and drew sports cartoons for the student newspaper, the Stanford Daily, and for the San Francisco Examiner and San Francisco Chronicle.

Following graduation in 1977, he spent a year as an artist and writer at Filmation Associates, a production company, working on animated shows including “The New Adventures of Mighty Mouse” and “Fat Albert & the Cosby Kids.”

He wrote an unsolicited script for “Taxi,” and it became episode 12 of season 3, in which Tony Danza’s character’s boxing license is revoked. He was hired as a staff writer and within a year, at 25, was one of the show-runners.

In addition to “Cheers” and “The Tracey Ullman Show,” Simon wrote for “It’s Garry Shandling’s Show” before landing “The Simpsons.”

His later projects included writing for “The Drew Carey Show,” creating a short-lived celebrity poker program, “Sam’s Game,” for Playboy TV, and managing the career of heavyweight boxer Lamon Brewster. His two marriages, to actress Jennifer Tilly and Playboy Playmate Jami Ferrell, ended in divorce.

Simon’s philanthropic work included freeing animals such as bears and chimpanzees from small zoos and circuses and moving them to sanctuaries. People for the Ethical Treatment of Animals named its Norfolk, Virginia, headquarters the Sam Simon Center.

One of his charitable endeavors provides vegan food to the poor. Another trains dogs to be adopted, to visit senior centers, to serve the hearing impaired and to help veterans diagnosed with posttraumatic stress disorder.

He restored the Richard Neutra-designed Bailey House in Pacific Palisades and accumulated an art collection including works by John Singer Sargent and Andy Warhol.

Reflecting on his TV work, Simon said: “In some ways, it’s the greatest job in the world. You make a product that’s given away, and all it does is make people smile. Nobody gets hurt, there’s no damage, and you can get crazy rich.”