It's 5:01 p.m., and you can tell from the doctors' bedside behavior that the patient has only hours left. Sagan Lewis, who usually commands these halls as the ever-conscientious surgeon Jackie Wade, is shirking her doctorly duties. Instead, Lewis is asking everyone to sign her surgical gown. Ed Begley Jr., known best for his irrepressible wisecracks as Dr. Victor Ehrlich, looks downcast, grave. "It's going to be hard to find another one like this," says Begley. "It's starting to sink in that it's over."

It is indeed. After six seasons, 12 Emmys and a reputation as the quirkiest show on NBC's prime-time schedule, St. Elsewhere is checking out. As the cast films the final scenes of episode No. 137, titled "The Last One," the atmosphere on Stage Three of the MTM lot in Studio City matches the peculiar mood of this peculiar show: black humor and blue punch lines, heartaches and headaches, sentimentality spiked with sarcasm. "Now what?" muses Jennifer Savidge, who plays caustic head nurse Lucy Papandrao. "Maybe I'll start to read." Howie Mandel, who plays corridor clown Dr. Wayne Fiscus, says, "This is the longest affiliation I've had with any institution, including school."

Like its most memorable patients, St. Elsewhere is not going gentle into that good night. Instead, "The Last One," which airs next Wednesday (May 25), ends Dr. Daniel Auschlander's six-year battle with liver cancer on an unconventional note. "I've had the longest-running remission in prime time, if not history," says Norman Lloyd, who plays Auschlander. The episode also marks the stormy return of administrator Dr. Donald Westphall (Ed Flanders), who left this season as a regular when he mooned his new boss—on-camera. And in a final twist that the producers are protecting as though it were Bobby Ewing in the buff, "The Last One" will somehow allow the St. Elsewhere cast to bid adieu. "People ask me, 'How will it end?' " says Howie Mandel. "I tell them: with credits."

Industrial-strength irony has always been a hallmark of St. Elsewhere, in its life and in its death. Here was a show that epitomized artistic excellence by chronicling the minute-by-minute mediocrity of a Boston hospital. Here was a series with critical-condition ratings that got renewed season after season. And since its producers have committed themselves to a new fall series, NBC's Tattinger's, about a New York restaurateur, St. Elsewhere is exiting just as it's starting to win its time slot.

In the beginning, St. Elsewhere was considered a bastard brother of Hill Street Blues. Nearly every review dutifully compared the ensemble cast, the overlapping dialogue and hand-held camera work with the precinct drama that preceded it. But as the show evolved, St. Elsewhere became something else: a sanctuary of literate scripts and idiosyncratic sensibilities—General Hospital as it might have been created by Woody Allen. In a medium that never allowed Marcus Welby to lose his patience, St. Elsewhere dared to kill off patients. Regularly. And it habitually threatened to give NBC censors coronaries. William Daniels, who won two Emmys as the arrogant heart surgeon Dr. Mark Craig, delivered the cast's favorite double entendre when his character said, "roses on the piano, tulips on the organ."

The show became most infamous for plot twists that were almost too twisted for prime time. A popular recurring character, Mrs. Hufnagel (Florence Halop), died when her hospital bed simply folded up on her. Pathologist Cathy Martin (Barbara Whinnery) preferred sex on a slab in the morgue to dalliance in a bedroom. "Let's see," says Christina Pickles of her character, nurse Helen Rosenthal, "I had five children, four marriages, breast cancer and in the end a drug problem. At least I wasn't raped."

"I think our viewers were always watching to see what was the next outrageous thing we'd get away with," says Mandel. "For them, St. Elsewhere was a drama-game show."

At 7:59 p.m., director Mark Tinker begins shooting the last scene. Suddenly Tinker—son of superproducer Grant—has an epiphany. "I just realized something," he says. "I can't fire anybody anymore." As emotions mount, there's a call for silence, but the onslaught of sniffles smothers the request. "I was in the first shot, and I'm in the last one," Pickles says to Tinker, who replies, "When I started this show, I had hair."

The scene ends 17 minutes later with Ed Begley embracing Jennifer Savidge on-camera. "That's a wrap, everybody," says a crew member, but the actors can't let go of each other. "It was a very emotional moment, and I didn't even see it coming," Begley says later. "That last embrace with Jennifer seemed so final." Hugs and kisses are now being exchanged. "I wasn't upset at all until I saw Ed sobbing in the corner like a 9-year-old," says Pickles. "Then I lost it too."

As the farewells continue, champagne glasses are filled at the nurses' station. Bleary-eyed, Tinker takes a clapboard and makes an early exit. Picking up her autographed surgical gown, Sagan Lewis says, "I'm going to be buried in this." For the cast and crew, St. Elsewhere has left significant scar tissue. "Emotionally, my last day on that set was the hardest day of my life," says Howie Mandel. "It's difficult to believe I don't have to know what a d-5 lactator ring is anymore. But I took home a medical jacket and a stethoscope. Maybe from time to time, my wife will let me feel her glands."