Correction: An earlier version of this obituary incorrectly reported that “The Boys From Syracuse” by Richard Rodgers and Lorenz Hart premiered on Broadway in 1942. It premiered in 1938. This version has been corrected.

Hugh Martin, a Broadway and film songwriter who composed three enduring classics introduced by Judy Garland, “The Trolley Song,” “The Boy Next Door” and “Have Yourself a Merry Little Christmas,” died March 11 at his home in Encinitas, Calif. He was 96. His niece, Suzanne Hanners, said a cause of death could not be determined.

All three of Mr. Martin’s best-known songs were featured in the 1944 MGM musical “Meet Me in St. Louis.” In addition to being a showcase for Garland, the film was recognized for its sparkling score, which brought a fresh complexity to the Hollywood musical.

The songs were credited to Mr. Martin and his musical partner, Ralph Blane, but in reality Mr. Martin wrote virtually all the songs in “Meet Me in St. Louis.”

“The Trolley Song,” with its effervescent opening — “Clang, clang, clang went the trolley, ding, ding, ding went the bell!” — became a No. 1 hit and was nominated for an Academy Award as best song.

The bittersweet “Have Yourself a Merry Little Christmas,” with words and music by Mr. Martin, became a holiday classic, recorded by more than 500 artists. In the 1944 film, Garland sang it to her younger sister, played by Margaret O’Brien, as they were about to move away from their childhood home.

Mr. Martin’s original lyrics were decidedly bleak: “Have yourself a merry little Christmas. It may be your last. Next year we will be living in the past.”

Garland complained that the words were too depressing. At first, Mr. Martin was adamant about using his original words, but when other cast members and director Vincente Minnelli voiced objections, he relented and composed a new set of lyrics:

Have yourself a merry little Christmas.

Let your heart be light.

From now on our troubles will be out of sight.

In 1957, when Frank Sinatra recorded the song for a Christmas album, he asked Mr. Martin for further changes to “jolly it up.”

Mr. Martin substituted “Hang a shining star upon the highest bough” for the next to the last line in the song, replacing the words sung by Garland: “Until then, we’ll have to muddle through somehow.”

In the years since, both versions have been recorded by artists as diverse as Tony Bennett, the Jackson Five, Ella Fitzgerald, Chrissie Hynde and the Pretenders, Twisted Sister, Garth Brooks, Christina Aguilera and Alvin and the Chipmunks.

Over time, Mr. Martin came to recognize that, without revised lyrics, his song might never have caught the imagination of the public.

Hugh Martin Jr. was born Aug. 11, 1914, in Birmingham, Ala., and was the son of an architect. He began to study music at age 5 and attended Birmingham-Southern College with the aim of becoming a classical musician.

But after hearing the music of George Gershwin, Mr. Martin became enamored of jazz and the theater and moved to New York at 19.

He occasionally sang on Broadway and was part of a vocal quartet in the late 1930s and early 1940s. He began to write musical arrangements for Richard Rodgers and Lorenz Hart (“The Boys From Syracuse,” 1938), Cole Porter (“DuBarry Was a Lady,” 1939), Vernon Duke (“Cabin in the Sky,” 1940).

His first collaboration with Blane was “Best Foot Forward” (1941), which included the rousing school song, “Buckle Down, Winsocki.”

In 1944, Mr. Martin enlisted in the Army and was about to be sent into combat during the Battle of the Bulge.

“Just about then ‘The Trolley Song’ hit the top spot on the ‘Hit Parade,’ ” he recalled to the San Diego Union-Tribune in 1997. “And right away, since entertainment for the GIs had a high priority, I was transferred to a touring soldiers’ show.”

Mr. Martin received a second Oscar nomination for best song for “Pass That Peace Pipe,” a song he wrote for the 1947 film “Good News.” He had four Tony nominations for his Broadway shows and was named to the Songwriters Hall of Fame in 1983.

During the 1950s, he was a vocal coach for several Hollywood stars and was Garland’s piano accompanist during her famous comeback at New York’s Palace theater in 1951.

“Of all the things I did well, the thing I did best was play for singers, like Judy Garland,” Mr. Martin told the Birmingham News last year. “When I played for Judy, that’s the best thing I ever did.”

In the 1970s, after recovering from a serious automobile accident, Mr. Martin became a devout Seventh-day Adventist. He accompanied gospel singer Del Delker on tours during the 1980s and later played piano in a Spanish-language church in California.

In his later years, “Meet Me in St. Louis” and “Best Foot Forward” were revived on Broadway, and Mr. Martin recorded a 1995 album with Michael Feinstein. He continued to compose new songs and musicals well into his 90s.

Survivors include a brother.

In December, more than 66 years after he wrote “Have Yourself a Merry Little Christmas,” Mr. Martin tried to explain his song’s enduring power.

“I didn’t write it for the soldiers overseas, or for young lovers,” he told the Union-Tribune. “I just wrote it for the movie. I tried to give them the best song I could.”