Broadway director and lyricist Martin Charnin, right, with composer Charles Strouse in 2013. (WENN Rights Ltd./Alamy)

Martin Charnin, a Tony- and Emmy-winning writer, director and producer who turned a Depression-era comic strip into “Annie,” the hit Broadway musical about a freckle-faced orphan with a “hard knock life,” died July 6 at a hospital in White Plains, N.Y. He was 84.

Mr. Charnin had suffered a heart attack three days earlier, said his daughter, Sasha Charnin Morrison.

Long before he conceived, directed and wrote the lyrics to “Annie,” Mr. Charnin was a Broadway actor playing a Jet in the original 1957 production of “West Side Story.” He had responded to a casting call for “authentic juvenile delinquents,” he later said, but found he had little inclination for singing and dancing.

Within two years, he shifted toward creative work behind the scenes, writing or directing off-Broadway revues for the impresario Julius Monk, as well as nightclub shows for artists including Shirley Jones, Abbe Lane, Leslie Uggams, Dionne Warwick and Nancy Wilson.

Collaborating with composers such as Richard Rodgers and his daughter Mary Rodgers, Mr. Charnin wrote the lyrics to Broadway musicals including “Hot Spot” (1963) and “Two by Two” (1970-71), and also directed television variety specials that earned him three Emmy Awards in the early 1970s.

All the while, he promoted and developed what he described as an optimistic musical for a cynical time, crafting a show that chronicled the feisty orphan Annie and her dog Sandy, the cruel caretaker Miss Hannigan and the balding millionaire Oliver “Daddy” Warbucks.

With a book by Thomas Meehan and a score by Charles Strouse, “Annie” opened on Broadway in 1977 and ran for 2,377 performances, spawning two Tony-nominated revivals, three film adaptations and countless local theater productions, with the New York Times estimating in 2012 that 700 to 900 “Annies” run each year in the United States alone.

In part, the musical’s success was driven by some of the cheeriest, most infectious songs ever performed on Broadway — including “It’s the Hard Knock Life,” which was sampled by rapper Jay-Z in 1998, and “Tomorrow,” in which Annie proclaims: “Bet your bottom dollar/ That tomorrow/ There’ll be sun!” The anthem became so ubiquitous it was sung by pro football players and coaches in a commercial for the NFL Network.

Mr. Charnin’s quest to stage “Annie” reportedly landed him $75,000 in debt by the time his musical opened on Broadway. He had first encountered the characters around 1970 (accounts vary on the year), when he came across a collection of Harold Gray’s “Little Orphan Annie” comics while shopping for a Christmas gift for choreographer Alan Johnson.

“He didn’t give the book to Alan,” Charnin Morrison recalled in a phone interview, “but kept it and thought, ‘Wow, what a great idea for a musical.’ ”

At first, few others agreed with him. Mr. Charnin insisted on casting children and dogs, unnerving potential financial backers. He rebuffed suggestions that he stage the musical as camp instead of straightforward realism. And he struggled to convince Meehan, who had previously worked with him on television projects, and Strouse, who composed “Bye Bye Birdie,” that the project could succeed.

“I said it was a horrible idea,” Meehan later told the Toronto Star, recalling Mr. Charnin’s early pitch. “Fortunately,” he added, “I changed my mind,” swayed in part by the original comic’s Dickensian themes of abandonment and triumph over poverty.

An early version of “Annie” premiered in 1976 at the Goodspeed Opera House in East Haddam, Conn., where a hurricane had just hit town, taking out the electricity and shortening the crew’s rehearsal time. A power outage delayed the curtain on opening night, and once the show got underway, scenery fell and cues were missed.

But Mr. Charnin tweaked the cast and retooled the show, leading it to be picked up by director Mike Nichols, who produced “Annie” for Broadway. Disliking the show, wrote New York Times reviewer Clive Barnes, “would be tantamount to disliking motherhood, peanut butter, friendly mongrel dogs and nostalgia.”

“It takes what could be the pure dross of sentimentality and turns it into a musical of sensibility,” he added, noting that Mr. Charnin’s lyrics were “bland to the point of banality,” perhaps intentionally so: “It is meant to be a show to experience, not a show to think about.”

The production was nominated for 10 Tony Awards, including best director, and won seven, including best musical, best book and best score, which Mr. Charnin shared with Strouse. He also received Drama Desk Awards for outstanding director and lyrics, shared a Grammy for best cast show album and reportedly made a fortune on the musical, which earned a profit of more than $20 million and fetched a record $9.5 million for film rights.

Mr. Charnin was unimpressed by the 1982 movie adaptation, directed by John Huston, and by subsequent films in 1999 and 2014. Remaining on Broadway, he received two Tony nominations for directing and helping film critic Joel Siegel craft the book for “The First,” a 1981 musical that starred David Alan Grier as Jackie Robinson but closed after one month.

For the most part, he remained consumed by the red-haired moppet who launched him to national prominence. He spent years working on a sequel, reassembling the original “Annie” team for “Annie 2” (1989), which premiered in Washington to disastrous reviews and was rewritten as “Annie Warbucks.” The production opened off-Broadway in 1993 and ran for 200 performances.

“ ‘Annie’ is riddled with joy, tempered by some satire, some sarcasm,” Mr. Charnin told the Associated Press in 2015. “Being optimistic is really not a bad thing to be. If you took it out of the equation of how you’d live, I think everything would be ‘The Hunger Games.’ ”

The oldest of two children, Martin Jay Charnin was born in Manhattan on Nov. 24, 1934, and raised in the city’s Washington Heights neighborhood. His mother was a secretary, and his father was a basso profondo at the Metropolitan Opera who wanted Martin to become an artist.

Instead, Mr. Charnin turned to theater after graduating from Cooper Union in 1955. In addition to “West Side Story,” he appeared in the 1959 revue “The Girls Against the Boys,” alongside comic actors including Bert Lahr and Dick Van Dyke.

He later wrote the Barbra Streisand song “The Best Thing You’ve Ever Done,” as well as lyrics for the Broadway shows “La Strada” (1969), written with Lionel Bart and based on the film by Federico Fellini; “I Remember Mama” (1979), with music by Richard Rodgers and a book by Meehan; and contributed to “The Madwoman of Central Park West” (1979), a one-woman musical comedy starring Phyllis Newman.

Mr. Charnin conceived and directed “Nash at Nine,” a 1973 revue drawn from poetry by Ogden Nash, and also directed Broadway productions of “A Little Family Business” (1982), “Cafe Crown” (1989), “Sid Caesar & Company” (1989) and “The Flowering Peach” (1994).

On television, he won an Emmy Award for the Anne Bancroft vehicle “Annie, the Women in the Life of a Man” (1970), followed by two more Emmys for “ ’S Wonderful, ’S Marvelous, ’S Gershwin” (1972), featuring Jack Lemmon and Fred Astaire.

His marriages to Lynn Ross and Genii Prior, who both danced in “West Side Story,” and to Jade Hobson, a creative director for fashion magazines, ended in divorce. In 2006 he married Shelly Burch, who starred in the soap opera “One Life to Live” and later appeared in nightclub shows directed by Mr. Charnin.

In addition to his wife and daughter, from his second marriage, survivors include a son from his first marriage, Randy Charnin; three children from his fourth marriage, Joel Bennett, Dayna Bennett and Richard Bennett; and three grandchildren.

In recent years, Mr. Charnin served as a guardian of sorts for the Annie character and story, directing at least 18 productions of “Annie” in addition to its original Broadway run.

“I don’t think I’ll ever have another ‘Annie,’ ” he once told the New York Times. “I think we all went on to our next projects thinking that kind of magic could happen again. But it will one day — for somebody else who pursues a pipe dream for a long time.”