NEW YORK — Loretta Swit, who won two Emmy Awards playing Maj. Margaret Houlihan, the demanding head nurse of a behind-the-lines surgical unit during the Korean War on the pioneering hit TV series M*A*S*H,” has died. She was 87.

Publicist Harlan Boll says Swit died Friday at her home in New York City, likely from natural causes.

Swit and Alan Alda were the longest-serving cast members on “M*A*S*H,” which was based on Robert Altman’s 1970 film, which was based on a novel by Richard Hooker, the pseudonym of H. Richard Hornberger.

The CBS show aired from 1972 to 1983, revolving around life at the 4077th Mobile Army Surgical Hospital, which gave the show its name. The 2 1/2-hour finale on Feb. 28, 1983, lured over 100 million viewers, the most-watched episode of any scripted series.

Rolling Stone magazine put “M*A*S*H” at No. 25 of the best TV shows of all time, while Time Out put it at No. 34. It won the Impact Award at the 2009 TV Land annual awards. It won a Peabody Award in 1975 “for the depth of its humor and the manner in which comedy is used to lift the spirit and, as well, to offer a profound statement on the nature of war.”

In Altman’s 1970 film, Houlihan was a one-dimensional character — a prickly, rules-bound head nurse who was regularly tormented by male colleagues, who gave her the nickname “Hot Lips.” Her intimate moments were broadcast to the entire camp after somebody planted a microphone under her bed.

Sally Kellerman played Houlihan in the movie version; Swit took it over for TV, eventually deepening and creating her into a much fuller character. Her sexuality was played down and she wasn’t even called “Hot Lips” in the later years.

The growing awareness of feminism in the ’70s spurred Houlihan’s transformation from caricature to real person, but a lot of the change was due to Swit’s influence on the scriptwriters.

“Around the second or third year I decided to try to play her as a real person, in an intelligent fashion, even if it meant hurting the jokes,” Swit told Suzy Kalter, author of “The Complete Book of ‘M*A*S*H.’ ”

“M*A*S*H” wasn’t an instant hit. It finished its first season in 46th place, out of 75 network TV series, but it nabbed nine Emmy nominations. It was rewarded with a better time slot for its sophomore season, paired on Saturday nights with “All in the Family,” then TV’s highest-rated show. At the 1974 Emmys, it was crowned best comedy, with Alda winning as best comedy actor.

The series also survived despite cast churn. In addition to Swit and Alda, the first season featured Wayne Rogers, McLean Stevenson, Larry Linville and Gary Burghoff. Harry Morgan, Mike Farrell and David Ogden Stiers would later be added, while Jamie Farr and William Christopher had expanded roles.

Toward the end, Swit was tempted to leave the show. She played the role of Chris Cagney in a 1981 television movie, “Cagney & Lacey” and was offered the part when it was picked up as a midseason series for spring 1982. But producers insisted she stay with “M*A*S*H” for its last two seasons.

In 1983, she married actor Dennis Holahan, whom she’d met when he was a guest star on “M*A*S*H” They divorced in 1995.

Born Loretta Jane Szwed on Nov. 4, 1937, in Passaic, New Jersey, the daughter of Polish immigrants, Swit enrolled in the American Academy of Dramatic Arts, then paid her dues for years in touring productions.

In 1969, she arrived in Hollywood and was seen in such series as “Gunsmoke,” “Hawaii Five-O” and “Bonanza.”

She would also regularly return to theater, starring on Broadway in 1975 in “Same Time, Next Year” and “The Mystery of Edwin Drood” in 1986.