For shows created strictly for laughs, things certainly get sad when it comes time to say goodbye.

The atmosphere was nearly funereal on the "Friends" and "Frasier" sets earlier this year when they were opened to reporters a few weeks before the finales were shot.

"Friends" ends its 10-season run Thursday. A week later, on May 13, "Frasier" ends its 11-year run - and a 20-year run for Kelsey Grammer's character Frasier Crane, introduced on "Cheers." Each hourlong finale is preceded by an hourlong retrospective.

"It's a deeper loss than I was expecting," says Lisa Kudrow of "Friends."

"It's going to be, for me, brutal," says co-star Matt LeBlanc.

Their pain will be eased by what is expected to be the highest rating for an entertainment program in years, commanding a Super Bowl-size $2 million for a 30-second spot.

Once, when a TV show ran its course or called it quits, it faded with a regular episode at the end of a season. Some of the highest-rated shows in TV history, though, have been finales to comedies. Shows' legacies seem to rest on how their finales rank with the best, putting extra pressure on writers who may also be exhausted or overcome by emotion about the end.

Writing the finale has "been really hard," says "Friends" co-creator David Crane.

"To be honest, we watched a bunch" of finales, says co-creator Marta Kauffman. "The ones we really liked are the ones that seemed to stay true to what the series was."

"`Bob Newhart,' `Mary Tyler Moore,' those worked well," says Kauffman.

On the "Newhart" finale, which aired in May 1990, the star wakes up to find that the entire seven-year run as a New England innkeeper had been a dream; he's in bed alongside Suzanne Pleshette, who had played his wife on his 1972-78 "The Bob Newhart Show."

On the final "Mary Tyler Moore," which aired in March 1977, new owners fire everyone at the TV station but Ted Baxter. The show's characters have a big cathartic hug, and after marching out of the office, Mary peeks back in and turns out the light.

"Yeah, `Mary Tyler Moore,' that's the gold standard, I think," says Crane.

The biggest audience ever for a comedy farewell was the finale of "M*A*S*H" on Feb. 26, 1983, which drew a record 105.4 million viewers. The finale for "Cheers" on May 20, 1993, attracted 80.4 million. More recently, 76.3 million tuned in May 14, 1998, when "Seinfeld" called it quits in a jailhouse-caper story that wasn't as well received as other, warmer sitcom finales.

And although Crane says "the `Larry Sanders' finale was brilliant," Kauffman says its celebrity-filled final taping of the Garry Shandling comedy in 1998 was not the kind of finale they wanted for "Friends."

"We felt, for this show, it was really important that it be true to the tone of the series," Crane says. "We knew it had to be something where you felt something and where hopefully you laughed a lot. And we were invested in the characters. I think there's some shows you're not invested in the characters. That's not what the show is about."

In fact, some say "Friends" has been less about comedy than it's been about the characters - pals whose progress has been as duly noted as in soap operas, especially in the push and pull attraction between David Schwimmer's Ross and Jennifer Aniston's Rachel, a spark that began in the very first episode, Sept. 22, 1994.

The two hooked up during the second season but then took an extended break the next. Their repeated coupling and uncoupling is what made the show "jump the shark," according to Jon Hein's website and book about moments when pop culture goes awry. The origin of "jump the shark" is an episode of "Happy Days" in which a surfing Fonzi jumped over a shark, a desperate effort to reverse the show's ratings decline, according to experts.

Though the characters have dated outside of their circle, the format almost dictated that the focus stay on the original half-dozen. So, as the show draws to a close, the married Monica (Courteney Cox Arquette) and Chandler (Matthew Perry) are about to have a baby and move to the suburbs. Phoebe (Kudrow) has settled down enough to get married, too (to Paul Rudd, earlier this season). Joey (LeBlanc) remains unattached, freeing him up for the only "Friends" spin-off yet announced, "Joey," set to take its place Thursday night at 8 in the fall.

(Still, nothing in the "Friends" finale is done to set up that story line, to be based in Los Angeles. "This show earned a right to go out on its own," LeBlanc says.)

Now, it's down to Ross and Rachel once more, as she is about to leave for a job in Paris. It's a finale uncannily like that of "Sex and the City" in February, when Sarah Jessica Parker's Carrie Bradshaw goes off to Paris, only to be persuaded to return to New York - and her friends - by a man who has been a recurring love interest.

"When we decided, OK, it's going to be [just another] episode of the show, it became a little bit easier," Crane says.

"One of the important things for us was that it still felt like an episode of `Friends,'" Kauffman says, "that it wasn't some gimmick superimposed on some episode but still felt like our show."

"We didn't want to do something high-concept or take the show out of the world of the show," Crane says. "It's hopefully a really good episode of `Friends,' but it's an episode of `Friends.' And what was great about this year is that we knew from the beginning it was absolutely the last season, so we could really plan for it and sort of start trains running in January and February, so hopefully the last episode feels earned and organic."

With any luck, the characters' story lines will be tied up, Kauffman says. "We want them to be happy and OK, and [for us] to feel good about saying goodbye to them."

The "Frasier" finale on May 13, by contrast, will be full of guest stars, including Anthony LaPaglia, Robbie Coltrane, Richard E. Grant, Laura Linney, Jason Biggs and Jennifer Beals. The setting is the wedding of Frasier's dad, Martin (John Mahoney), to Ronee, played by Wendie Malick.

Whatever happens, it's clear the "Frasier" finale will be overshadowed by Thursday's "Friends" event.

"It will be more of a, I guess, social phenomenon for `Friends' to leave than it will for `Frasier,'" says Grammer. "So we will accept that. We've always been, creatively, I'd like to think, setting a very high bar. And we can go out saying that we continued that to the end."