The version of Sean Hayes who arrived at a Midtown Manhattan rehearsal space on a Wednesday morning last month was the one everyone knows from his years as a television star on the series “Will & Grace” and as an entertainer. The effervescent Hayes tossed off a quip about the perceived snobbishness of the Hamptons. (“It’s like Shake Shack,” he said. “Anybody can go. It’s not that fancy.”) With similar ease, he sat at a piano and played a few measures of “Rhapsody in Blue.”But the Hayes who a short while later entered through the door of a set made to look like a 1950s-era TV dressing room was markedly different. His eyes were squinted and his posture was hunched. He occasionally twitched his head or shook his hands. He spoke with the defeated voice of a jowly man, sometimes dropping a one-liner (“Gee, I wonder who died,” he said, contemplating the flowers in his room) and sometimes becoming so vehement that his face turned red and a vein bulged from his neck.This is how Hayes alters himself to play Oscar Levant, the pianist and raconteur, in the new Broadway play “Good Night, Oscar,” which opens on April 24 at the Belasco Theater. Levant, who died in 1972, was as renowned for his interpretations of George Gershwin’s music and his roles in films like “An American in Paris” as he was for his dyspeptic appearances on TV game shows and talk shows, jesting ruefully about his struggles with mental health and prescription drug addiction.The play, written by Doug Wright and directed by Lisa Peterson, imagines Levant on a fateful day in 1958 when he has finagled his way out of a psychiatric hospital to be interviewed on Jack Paar’s “Tonight Show.”Beneath its Eisenhower-era period details, “Good Night, Oscar” sets out to comment on enduring ideas about the burdens of celebrity and creative genius. Whether it succeeds will depend largely on Hayes’s ability to embody the dour Levant, a sort of public neurotic who may no longer be familiar to contemporary audiences.Oscar Levant circa 1947. He’d crack wise about the fragile state of his mental health, and once said, in answering a question about what he did for exercise, “I stumble and then I fall into a coma.”FPG/Archive Photos, via Getty ImagesBut as Hayes explained, these kinds of challenges are exactly what makes the play compelling to him.“If you’re not scaring yourself as an actor, what are you doing?” he said. “If everything’s safe, then the results will show that.” With this play, he added, “I’m going to swing for the fences. If it works, great. If it doesn’t, I’m still alive, right?”Hayes, 52, was sitting in a small room at the rehearsal space. He wore a zip-up sweatshirt and playfully shook his hair, a mixture of copper and silver strands, which he has grown out so it can be styled like Levant’s wavy coif.Though he rose to fame in his Emmy Award-winning role as Jack McFarland, the irrepressible “Will & Grace” sidekick, Hayes has his own complicated history as a pianist. When people in the industry are surprised to discover his musical roots, Hayes reminds them — with mock chagrin — that he played piano when he hosted the 2010 Tony Awards. “I’m like, did you not watch the Tonys?” he said. “I thought we all watched them together.”The youngest child of a mother who raised him on her own, Hayes started receiving piano training at age 5 from a neighbor in Glen Ellyn, Ill. (When his mother asked if he wanted lessons, Hayes said he replied, “I’m not doing anything else.”)By his teens, Hayes was playing Mozart sonatas and performing in competitions. But during high school and college (and a stint as music director at a dinner theater), he could feel himself being pulled away by the allure of acting — and weighed down by the pressure of classical performance.During concerts, Hayes said he found himself thinking: “The notes are the notes. These are the notes Beethoven wrote. These are the notes Chopin wrote. These are the notes Rachmaninoff wrote. And if you miss one of those notes, everybody notices.”With acting, he said, “I released myself of that pressure — and found a new pressure of always having to deliver on good material.”Similar anxieties — though amplified — prey upon the Levant depicted in “Good Night, Oscar.” Wright, the Pulitzer Prize-winning playwright of “I Am My Own Wife,” described his incarnation of Levant as a Jazz Age Salieri, in thrall to George Gershwin and crushed by a self-imposed perception that he never measured up to his idol.Levant’s interviews with Paar are their own little sliver of TV history — shocking to audiences in their day and still potent for their candor. Levant would crack wise to Paar about his hospitalizations, the prescriptions he was taking or abusing, and the fragile state of his mental health. In a 1963 appearance, Paar asked him what he did for exercise. Levant answered, “I stumble and then I fall into a coma.”When Levant returned to the program a few months later, the host opened the show by telling his audience that Levant was “much better now” and that he would never “use or bring somebody out on this stage who was not completely well.”During that interview, Levant said his recent behavior had been “impeccable”: “I’ve been unconscious for the past six months,” he explained. “I’ve been doing extensive research in inertia.”Hayes starred with Debra Messing, left, and Eric McCormack, center, in “Will & Grace,” playing the irrepressible Jack McFarland.THOUGH FRIENDS HAD SUGGESTED he consider playing Levant, Hayes was not especially familiar with the pianist. As it emerged in 2009 that DreamWorks was developing a possible Gershwin biopic, intended for the director Steven Spielberg, in which Levant was a minor character, Hayes said he went so far as to commission his own hair and makeup test to see if he could at least look like Levant. (The film was not produced.)As he learned more about Levant, Hayes said he began to feel an affinity for him. “The mental health issues are in my family,” Hayes said. “Addictions are in my family. I thought, maybe I can wrap my head around this thing. As an actor, that’s what we do.”After Hayes’s Tony-nominated run in the 2010 Broadway revival of “Promises, Promises,” he and the show’s executive producer, Beth Williams, began discussing a possible Levant project for the stage. They later brought in Wright, who had been the screenwriter of the Gershwin film.Wright said he, too, was fascinated by Levant, having grown up with “a really entertaining, outrageous, brilliant father who was severely bipolar and refused medication, so Oscar’s mood swings were really familiar to me.”After a lunch meeting where Hayes demonstrated how he would play Levant, Wright said, he left “more passionate about it than ever before.”Asked how he gets himself into character, Hayes told a story of himself as a novice actor, playing an elf in a Kenny Rogers Christmas stage show. As the director increasingly asked the elf-actors to take on more of the duties of stagehands, Hayes said he told her, “You know we’re not really elves — we’re just playing elves.”In similar fashion, Hayes said, “I’m not really Oscar Levant. I’m playing Oscar Levant. This is my interpretation of Oscar Levant.”Long before the play’s 2022 debut at the Goodman Theater in Chicago, Hayes said he had been working on Levant’s voice, mannerisms, tics and physical bearing. He continues to refresh himself on those elements even now, though Hayes said he is not one of those actors who remains in character outside of rehearsals and performances.Reviewing that production for the Chicago Tribune, Chris Jones wrote that Hayes “displays talents here most of his fans will have no idea he had at his disposal,” adding that he delivers “a stunner of a lead performance: moving, empathetic, deeply emotional and slightly terrifying.”The announcement last year of the play’s Broadway transfer drew a rebuke from the playwright David Adjmi, who wrote in a Facebook post that he had persuaded Hayes to take on Levant and was commissioned by Williams to write a play for the actor.When Adjmi refused to “lighten the material,” he said Williams and Hayes replaced him with Wright while using their option on Adjmi to prevent him from further developing his play.At that time, the “Good Night, Oscar” producers said Hayes and Adjmi had parted ways over “different creative visions.” Hayes, in his interview, declined to revisit the matter. “We’ve already responded to that,” he said.Wright said that he had spoken with Adjmi “to ensure that it would not be awkward if I proceeded with the project, and he couldn’t have been more generous.”“I have to now perform in front of a live audience,” Hayes said of playing the piano onstage. “But it’s different this time. Because I don’t care if I miss a note.”Luisa Opalesky for The New York TimesAdjmi wrote in an email that though he felt Hayes and Williams’s actions were “morally objectionable,” he told Wright that “it was not my place to tell him or any writer what job to take.” Adjmi said he later learned from his agents that Wright had taken the job.THERE REMAINS THE QUESTION of whether Hayes felt a personal connection to Levant that made him want to play him, but the actor seemed comfortable cultivating this air of ambiguity.Jason Bateman, a longtime friend of Hayes’s and a co-host of their popular SmartLess podcast, said he did not necessarily notice that Hayes was striving to play damaged dramatic figures.“If you’re asking, have I sensed a darker, more mysterious side of him, I would say no,” Bateman said. “Being able to sincerely be in a place of joy, openness and honesty already takes a great deal of emotional and spiritual intelligence.”Having made his own transition from comedies like “Arrested Development” to thrillers like “Ozark,” Bateman said it can be sufficiently satisfying for an actor “just sticking around long enough to show audiences the rest of what’s in your trick trunk.”Wright proposed an explanation rooted in a connection he felt he shared with Hayes. “We both have cultivated some pretty affable, convivial exteriors,” Wright explained. “But I think that’s a survival mechanism, being gay men in a hostile world and needing to be liked, to keep ourselves safe a lot of times. That conviviality conceals some darker waters, and that’s how he accesses Oscar.”Hayes remained coy. “In order to play the darker side of Oscar, I do tap into certain aspects and experiences of my life,” he said, “but those are between me and Oscar.”In the rehearsal studio, Hayes said he found it fitting and illuminating that, having set aside his musical career so long ago, he should choose a role that requires him to play piano in the guise of someone filled with self-doubt about his own proficiency with the instrument.“I have to now perform in front of a live audience,” he said. “But it’s different this time. Because I don’t care if I miss a note.”If Hayes makes a mistake, he can always say that he was doing it in character. “It’s organic to the material in the play,” he said. “And I’ve finally realized, nobody’s perfect.” More