Last week's "Rescue Me," the penultimate episode of the FX firefighting drama, spent most of its running time on the wedding of Tommy Gavin's eldest daughter Colleen to his colleague Black Shawn. It was a long sequence, alternately funny and unbearable. Then the episode segued rather abruptly into one of its hairiest, most riveting fire sequences ever, as Tommy and the rest of the guys on 62 Truck became trapped in an arson fire after turning away from a waiting escape ladder to try to rescue a few more civilians. Their only exit blocked, best friends Tommy and Lou faced each other, unsure of what to do next...

...and then the building blew up.

The episode was, in other words, seven seasons of "Rescue Me" in a nutshell: at times hilarious, at times obnoxious, and then so riveting that you will almost forgive it every one of its past sins.

Almost.

"Rescue Me" debuted in July of 2004, nearly three years after 343 members of the FDNY died while helping evacuate the World Trade Center on 9/11. Other TV series would make 9/11 an occasional subject, or a clear theme ("24," "Battlestar Galactica"), but no drama was as bluntly, consistently about that horrible day in the way that "Rescue Me" was. Denis Leary's Tommy had been at the Twin Towers that morning, had lost his cousin Jimmy in the collapse, and had in turn let his own life fall down around him. He drank too much, fought too much with his wife Janet, took too many risks on the job, and saw ghosts - Jimmy, other 9/11 firefighters, people he'd failed to save - everywhere he turned.

Even three years out, the subject matter of "Rescue Me" felt incredibly raw and powerful. Both Leary and co-creator Peter Tolan (who had previously teamed on ABC's short-lived cop dramedy "The Job," with Leary as a similarly self-destructive hero) came from comedy backgrounds, and they managed to mix in just enough raunchy humor to make all the 9/11 angst bearable. The episode "Inches," an early highlight from the first season, mixed together Tommy having a nightmare about being in the World Trade Center lobby, the guys at the firehouse having a contest to see who was the most well-endowed, and the random death of a member of the crew in a fire that had seemed under control. The show's philosophy seemed to be, "If you don't laugh, you'll cry - but then you'll probably cry anyway, and scream, and then tell a few dirty jokes to stay sane." And both in front of and behind the camera, Leary and Tolan provided further evidence to the theory that it's much easier for comedians to go dark than for serious actors and writers to learn how to be funny.

As the series got further away chronologically from September 11, 2001, though, it also moved further from its thematic roots. Though 9/11 was never exactly forgotten, the show became less about its effects on the FDNY in general and this one man in particular and more of a mid-life crisis dramedy about an alcoholic who was also completely irresistible to women and a better man and firefighter than everyone else he worked with.

(It wasn't enough for the show to do the usual cliche about the anti-hero whose personal life is a mess but who gets it together on the job; no, Tommy had to be better, braver and wiser than the other guys and get the moral high ground in nearly every professional argument, on top of having every female guest star throw herself at him. Suffice it to say that if a version of the show existed without any on-screen credits, viewers would still be able to tell that Leary had co-written the vast majority of episodes.)

Leary, Tolan and company piled a laughable amount of tragedy on Tommy, at various points killing off his son, brother and father, among (many) others, and had Jimmy's son Damian join 62 Truck just long to suffer permanent brain damage on the job. (At least Damian gets to maintain a presence on the series, where Jack McGee's Chief Jerry Reilly ate his gun and was almost instantly forgotten. For that matter, it took the writers a long time to realize that it might be a good idea for Tommy to, you know, grieve his dead son.) And there were other creative missteps, like a violent sexual encounter between Tommy and Janet that many viewers (this one included) took for rape, even as the show tried to treat it as a moment of triumph.

And yet the very messiness of the show  - the way episodes often seemed to be put together at random, with one scene having almost no story or emotional connection to the next - made it worth watching even in those dark, self-indulgent middle seasons, because you never knew when the show would be capable of delivering a random powerhouse dramatic moment, or a tasteless gag so funny that you'd accept all the dross around it as the price of admission.

On the other hand, those increasingly-rare moments of genius could make some of the stupid stuff even more frustrating. As Jimmy's widow - and Tommy's sometime-lover - Sheila, Callie Thorne was stuck most of the time playing one of the most shrill, cartoonish, genuinely unpleasant characters in all of primetime. Every now and then, though, the writers would allow Sheila a moment of honesty and dignity, where they would acknowledge that she wasn't just an irritating nag, but a very damaged person who was in her own way haunted at least as much as Tommy. And good as those were, they mainly made me despair that the same people capable of crafting those moments would usually just take the path of least resistance and treat Sheila as a clown. (Unsurprisingly, the worst scene last week involved Sheila delivering a long, drunken, mortifying wedding toast.)

The fifth season was, for a while, a strong step back in the right direction, as the show returned to its 9/11 roots with a story arc about a journalist stirring up bad old memories while preparing a book for the 10th anniversary. It was not only a return to the show's strongest subject matter, but a story arc that steered the series away from its one-man-show style and allowed supporting actors like John Scurti and Steven Pasquale to take some of the load off Leary's shoulders. But by the end of that season (unusually long for cable drama standards), 9/11 was again largely ignored and we were back to women literally fighting in the street over Tommy.

At that point, I threw up my hands and resolved to quit the series, but I've been inevitably drawn back from time to time, and this final season has offered some reminders of the show's strong early days. Maura Tierney (acting at a time when she was in the middle of her cancer treatments) reprised her role as one of Tommy's would-be conquests, and she and Leary were electric together as their characters grappled with all they had lost. And the firefighting scenes themselves have remained the one area where the series has never really lost its footing.

Given the way last week's episode ended, I can't say much about tomorrow night's series finale (I'll have another post going up after it ends), save that it has some strong moments and some stupid ones. Which seems about right for "Rescue Me."

Alan Sepinwall may be reached at sepinwall@hitfix.com