Last fall, as show No. 13,781 of “The Phantom of the Opera” came to a close, the applause overpowered the thundering music. The members of the orchestra, packed into the pit under the stage, could not see the crowd, but they could hear and feel them.

The standing ovation brought Kristen Blodgette, the show’s associate conductor, to tears. She held her red-nailed hands in prayer, in gratitude to the musicians.

Andrew Lloyd Webber’s smash hit — the longest-running musical in Broadway history — is scheduled to give its final performance at the Majestic Theater next month. These days, since the announcement of the closing last September, the musical “feels more like a rock concert,” said Kurt Coble, a violinist with the show.

Mr. Coble is part of Broadway’s largest pit orchestra, which will disappear along with the show. It holds 27 full-time musicians, 11 of whom have been with “Phantom” since it opened in the late 1980s. The consistent work has allowed many of the longtime musicians, who have essentially grown up and older with the show, to build comfortable, even lucrative lives. And that is no small feat for any artist seeking stability in New York City.

Unlike the actors who have short-term contracts with “Phantom,” full-time musicians get a “run-of-show” agreement, which guarantees their jobs until the production closes. In 1988, when “Phantom” first opened, “there were some wide-eyed optimists who thought the show could run as long as five to six years,” recalled Lowell Hershey, a trumpeter who has been with the production since the beginning. “And I remember thinking, ‘Wow, that would be really good.’”

“Phantom,” of course, surpassed that prediction. During its 35-year-run, the musical has created more jobs and generated more income than any other show in Broadway history, according to Michael Borowksi, its press representative.

The security of the “Phantom” paycheck has helped many of its musicians start families, send children to college, buy property, save for retirement. “Broadway was never meant to be a steady job, but for us, it was a steady job,” said concertmaster Joyce Hammann, who has been with “Phantom” since 1990. “I can’t overstress how unbelievably lucky we have all been for all these years.”

“Phantom” maintains a traditional pit setup, a sunken open cave wedged between the audience and the stage. Although live music remains one of the essential elements of a Broadway musical, many producers have sacrificed pits to build bigger stages or increase seating. These days, it’s common to see musicians onstage with performers, or to not see them at all, as many of them work in distant rooms that pipe their music into the theaters.

“Even if we want our musicians to be in the pit, the decision lies in how each production believes it will succeed,” said Tino Gagliardi, the president of Local 802 of the American Federation of Musicians. “Unfortunately, they are not always right — the shows that have had the longest runs have been the shows with large orchestras in the pit.”

Mr. Coble knows how special the pit experience can be. “Sometimes I feel like I am a blacksmith in the early 20th century, people still had horses but not as many,” he said. “But you can never get rid of musicians. You’ll always need live music.”

Pit musicians might not be able to see the show as it unfolds, but they have their tradecraft down pat. “Phantom” runs like a clock. The chandelier always swings over the pit, marking the beginning of the show, and then comes crashing down at the climax of Act 1. The patter of footsteps overhead marks the New Year’s Party in Act 2, which tells the musicians to make way for an actor who snakes his way through the pit and sits below the conductor, waiting to fire a shot into the auditorium. Then, when the shot sounds, they cover their ears and wait for the smell of powder, which signals that it is time for them to pick up their instruments again.

Regardless of whether they have a chair on Broadway (a full-time contract) or not, musicians are paid per show and are supported by Local 802, a strong union that provides them with health care and a pension, among other benefits. (When Broadway shows went dark during the pandemic, “Phantom” producers continued to pay the health insurance for their chair musicians.)

Ed Matthew, a clarinetist, said that when he started playing on Broadway in 1994, he made about $140 a night. As of this month, the base wage for a musician at “Phantom” is about $291 per show.

Before getting hired by “Phantom,” many of its musicians juggled jobs. Peter Reit, a French horn player, made fur coats in the garment district, tended bar and sold vacuum cleaners before joining the orchestra in 1987, when rehearsals for the musical started.

“I used to do my budget week to week with all my freelance work, and the first thing I noticed when I had this job was that I could now budget month to month, and that was an incredible stress relief,” said Mr. Reit, 63, who retired in 2021. He now teaches music at SUNY Purchase and Vassar College.

The regular pay and benefits allowed members of the pit to concentrate on other aspects of their lives, like raising children. “Most of the support for my family was based upon what I could earn, and that took a lot of pressure off as a provider,” said Mr. Hershey, the trumpeter.

Ms. Hammann, the concertmaster, has an 18-year-old son who grew up in the theater. When he was a baby, he sat with the stagehands while she played the show. “To have had the flexibility when I needed to be home with him, that’s not something one is able to do in many work environments, so it’s been tremendous,” she said.

In the late ’80s, when Ms. Blodgette, the associate conductor, was eight months pregnant with “the first ‘Phantom’ baby,” as she calls her daughter, the show’s conductors, who were all men, wore tuxedos, she said. She opted for a dress. Thirty-four years later and now a grandmother, Ms. Blodgette wears a thick velvet black gown with black socks (and no shoes) because she likes “to feel grounded” while conducting.

Broadway chairs may play up to eight shows a week and are required to attend at least 50 percent of the shows per quarter, according to union rules. This allows some musicians to work side gigs for extra money and to pursue passion projects. When Mr. Matthew, the clarinetist, joined the company in the early aughts, he was able to hold onto his job at G. Schirmer, a classical music publishing company. The combined paychecks allowed him and his wife to buy a co-op apartment in Long Island City, Queens, and to save for retirement, he said.

Mr. Coble, the violinist, joined the pit 25 years ago. Though grateful for the stability, he still yearns for more creative outlets. “I think of myself more like an artisan than an artist because I have very little freedom when it comes to playing music by someone else,” he said.

But the flexibility of his work schedule has allowed him to write scores for horror films and to play, as his mother likes to call it, “unpopular music.” When he is not working at the Majestic, he spends his time with the PAM Band (Partially Artificial Musicians), a robotic orchestra that he built to play whatever songs he wants. Now that “Phantom” is coming to an end, he said, “I’ll spend a lot more time on my own project, but it’s certainly not as well-paying as the show.”

There are five substitute musicians on call for each Broadway chair. Although substitutes receive the same union benefits as full-time chairs, they lack the consistency of an eight-show week. “Being a sub is hard because you are constantly waiting for the next call, you have no control in your life,” said Nick Jemo, a trumpeter who started subbing at “Phantom” in 2009 before joining the pit full-time five years later. Some subs have been filling in at “Phantom” for more than 10 years, and they keep coming back.

“You want to bring your entire being into that show — it’s got everything you’d ever want to express in an instrument,” said Brad Bosenbeck, who started subbing for one of the two viola chairs at “Phantom” when he was 26. Mr. Bosenbeck, now 31 and still a substitute, said he doesn’t take the job for granted. “I feel like the luckiest guy in the world that I get to do what I love and get paid for it.”

With the show’s closing, many of its musicians are thinking about their next chapters. Some believe that “Phantom” might return to Broadway in a few years with a reduced orchestra, like the production in London. A few veteran musicians, including Mr. Hershey, will retire. Ms. Hammann looks forward to teaching, which she started doing when the pandemic kept her away from the pit. Ms. Blodgette will conduct at “Bad Cinderella,” Mr. Lloyd Webber’s new musical. Most say they will try to sub at other shows.

“The show closing feels liberating,” said Mr. Coble, who admitted to fantasizing about being a strolling violinist in a fancy restaurant, dressed up as the phantom and playing variations of the score. “I’ll play my last performance like I’ve tried to play every other show, and when it’s over I’ll just move on to something else. I don’t get terribly sentimental over it because it’s a job after all, it’s work, it’s not easy, it’s not a vacation.”

The musicians won’t miss some aspects of the show, like the claustrophobic pit, where they sit so close to each other that if one of them opens a candy bar the rest can smell it. “We have to get along with each other because we are tucked in like sardines in a can,” Mr. Matthew said. “You don’t want to take up too much space and you also want to fit in.” The radio program “This American Life” produced a segment a few years ago about some of these frustrations.

Despite the intimate, tense energy of the “Phantom” pit — “it is its own magical elixir,” Mr. Bosenbeck said — most musicians said they didn’t have many opportunities to connect with each other outside the theater. “One of the things that makes this ending bittersweet is that everyone has been in my life for so long and I’ve been in theirs for so long, and yet we didn’t get an opportunity outside of waiting in the bathroom line or arriving early to really speak to everybody,” Ms. Hammann said.

During these final weeks, as audience members watch the tortured love story onstage, the pit musicians will continue their routine underneath it. A ghostly image of Ms. Blodgette will appear on four small screens scattered throughout the orchestra so musicians can follow her lead. Mr. Jemo, after a temporary stint with “Bad Cinderella,” will return, repositioning his chair to catch a glimpse of his girlfriend, a dancer in the show. One music stand will continue to showcase a collection of miniature toys — a smiling crocodile, a head-shaking turtle, a deer’s face and a tiny plastic hand holding fresh radishes.

“I may be the only musician in the world who has radishes in their music stand,” said Karl Bennion, a cellist who accidentally took the vegetable to a show in 2017 and since then has made it a tradition.

In between songs, some musicians will play Sudoku and crossword puzzles; others will read. “A good book can really make going to work even more joyful,” Mr. Jemo said. He and Mr. Hershey, his trumpet partner, had a big French dictionary that sat between them, and often they reached for it at the same time.

At the end of every show, musicians will continue to interact with audience members, some of whom like to peek into the pit to thank them as they pack their instruments.

“What more can we ask for than to have had this show for 35 years?” Ms. Blodgette asked. “When I started doing this, I was single, I did not have a child, my parents were alive,” she said. “Through all of the chaos of life, this was here.”