Peter Scolari, a versatile comic actor who had television roles in “Bosom Buddies” and “Newhart” in the 1980s and won an Emmy Award in 2016 as Lena Dunham’s father in the HBO comedy series “Girls,” died Oct. 22 in New York City. He was 66.

His death was confirmed by Ellen Lubin Sanitsky of Wright Management. The cause was cancer.

Mr. Scolari, who had a youthful, wiry appearance throughout his career, appeared in several films but was far better known for his work in television and theater. His breakout role came in “Bosom Buddies,” a farcical ABC-TV comedy that premiered in 1980 with Mr. Scolari and Tom Hanks playing advertising copywriters who are thrown out of their New York apartment.

They dress as women to conceal their identities — reviving a hoary showbiz trope perhaps done best in Billy Wilder’s 1959 comedy “Some Like It Hot,” with Tony Curtis and Jack Lemmon, and in “Tootsie,” a 1982 film starring Dustin Hoffman.

Hanks (as Kip) and Mr. Scolari (as Henry) find a room in the all-female Susan B. Anthony Hotel. Passing themselves off as Buffy and Hildegard, they comically juggle their real and assumed identities while negotiating the pitfalls of work and romance.

Some critics dismissed the series as “Some Like It Lukewarm,” but audiences wrote so many enthusiastic letters to ABC that it was renewed for a second season.

“We really took a beating in the press, got hammered for it the first few weeks,” Mr. Scolari told the Los Angeles Times in 2010. “But when Dustin Hoffman comes out with ‘Tootsie,’ everyone goes, ‘Ooooh, masterpiece.’ ”

“Bosom Buddies” lasted only two years, but it has often appeared on lists of television shows that were canceled too soon. It launched both actors’ careers, with Hanks becoming a Hollywood superstar and Mr. Scolari finding more modest success on the small screen. They remained close friends.

Mr. Scolari later became a regular on “Newhart,” comedian Bob Newhart’s second CBS sitcom, which was set in a quaint and eccentric Vermont village and aired from 1982 to 1990. Mr. Scolari played a cocksure, if sometimes vacuous, television producer, Michael Harris, who persuades Newhart’s character to host a local show.

Michael remains devoted to his girlfriend, Cupcake (played by Julia Duffy), despite various obstacles and temptations. In one scene, Michael’s female doctor (played by Melanie Chartoff) says she can no longer treat him because of her feelings for him.

“There’s something, I don’t know, erotic about you,” she says.

“Did you say ‘erotic’ or ‘neurotic’?” Mr. Scolari’s character responds.

Mr. Scolari was nominated for three Emmy Awards for “Newhart.” He considered the show’s namesake star, known for his understated, deadpan style, a major influence on his acting career.

Over the years, Mr. Scolari appeared in dozens of TV shows, including “The Love Boat,” “Ally McBeal,” “The Family Album,” “ER” and “The West Wing.” From 1997 to 2000, he had a central role in “Honey, I Shrunk the Kids: The TV Show,” portraying an oddball inventor originally played by Rick Moranis in the 1989 film hit. He had a voice role in the 2004 computer-animated Christmas movie “The Polar Express,” which also included Hanks.

Onstage, Mr. Scolari appeared in replacement roles in the long-running musicals “Hairspray” and “Wicked.” He reunited with Hanks in a 2013 Broadway production of “Lucky Guy,” a Nora Ephron play about a New York tabloid journalist.

In “Magic/Bird,” a 2012 play by Eric Simonson about basketball stars Magic Johnson and Larry Bird, Mr. Scolari played five separate roles, including those of Boston Celtics general manager Red Auerbach and Los Angeles Lakers coach Pat Riley and team owner Jerry Buss.

In 2014, Mr. Scolari — a standout high school baseball player — appeared in Simonson’s “Bronx Bombers” as baseball great Yogi Berra, playing opposite his wife, Tracy Shayne, as Berra’s wife, Carmen. He also acted in off-Broadway plays and touring productions of “Biloxi Blues,” “Grease” and “The Music Man,” among others.

From 2012 to 2017, Mr. Scolari found a new generation of fans as Tad Horvath, the father of Dunham’s character on “Girls,” a hit comedy on HBO. For the first few seasons, he was a standard Midwestern father, but as the series went on, his character became more interesting and complex, eventually coming out as gay.

Mr. Scolari was not initially nominated for an Emmy Award for the role. He replaced another actor who had appeared in too many episodes to qualify in the category of guest actor in a comedy series, then went on to win the Emmy.

In an Instagram post, Dunham called Mr. Scolari “the shyest extrovert, the most dramatic comedian, the most humble icon.”

In the wake of winning the Emmy, Mr. Scolari wryly noted, he was getting turned down for better parts.

“A measure of my success is how high-end the rejections are that I face,” he told the Kansas City Star in 2019. “If I lose a role to a movie star at this time in my career, then I’m doing OK. Because now I’m in the running.”

Peter Thomas Scolari was born Sept. 12, 1955, in New Rochelle, N.Y. He said he grew up in a tumultuous household in which “Mom was a recovering alcoholic, still more than 40 years sober, while Dad was a lawyer and a rageful man.”

Mr. Scolari excelled in sports, but his focus changed when he had the lead role in a high school production of “How to Succeed in Business Without Really Trying.”

“I did a scene,” he told the Toronto Star in 2008, “got some laughs, walked offstage, and then bam! I had a white-light experience. This is it, I thought. This is what I want to do with my life. I’m going to be an actor.”

He attended Occidental College in Los Angeles and City College of New York, where he became part of a theater group that included Danny DeVito, Jeff Goldblum and Rhea Pearlman. He learned how to juggle, walk on his hands and walk on a tightrope.

Before “Bosom Buddies,” Mr. Scolari appeared in several films and TV shows, including a regular role in “Goodtime Girls,” a short-lived comedy series set in Washington during World War II.

In an interview with the Oprah Winfrey Network, Mr. Scolari said he had a bipolar disorder and struggled with drugs and alcohol until his late 40s, when he joined a 12-step recovery program.

His marriages to Lisa Kretzchmar, Debra Steagall and Cathy Trien ended in divorce. Survivors include his wife of seven years, Tracy Shayne; two children from his second marriage; two children from his third marriage; a sister; and a brother.

Mr. Scolari remained in demand as an actor until his death, playing a corrupt police official in the TV crime drama “Gotham” from 2014 to 2019 and a show business manager in the 2019 miniseries “Fosse/Verdon.” Some of his final screen appearances came this year in “Evil,” a dark TV drama about demonic possession and the supernatural in which he played a Catholic bishop.

Mr. Scolari had become accustomed to people recognizing his face but not quite knowing who he was.

“When people say, ‘I know you. What have I seen you in?’ ” he said in 2019, “I respond, ‘Well, it depends on how old you are.’ ”